使用Power Query加载网页数据未找到表格仅显示Document的求助
Hey there! The issue you're facing is super common—websites like Box Office Mojo often update their HTML structure over time, which means the table your book referred to as "table 0" isn't where Power Query expects it to be anymore. Automatic table detection in Power Query relies on consistent markup, so even small changes to the site can break that.
Here are a few practical methods to get the table data you need:
1. Manually Dig Into the Document
Instead of stopping at the Navigator screen, click "Transform Data" to open the Power Query Editor. Follow these steps:
- You’ll see the "Document" loaded as a list of HTML elements. Start expanding the list items (click the arrows next to each entry).
- Look for elements where the "Name" column says
table—use the filter in the column header to search for "table" to narrow things down quickly. - Once you spot the right table (it should contain the box office rankings and gross data), expand it to pull in the rows and columns.
2. Use Custom M Code to Target the Table Directly
Skip automatic detection and use Power Query’s Html.Table function to extract the table using CSS selectors. Here’s a starting code snippet you can tweak:
let Source = Web.Contents("http://www.boxofficemojo.com/alltime/world/?pagenum=1&p=.htm"), HtmlDoc = Html.Document(Source), BoxOfficeTable = Html.Table(HtmlDoc, { {"Rank", "tr td:nth-child(1)"}, {"Movie Title", "tr td:nth-child(2)"}, {"Worldwide Gross", "tr td:nth-child(3)"}, {"Release Year", "tr td:nth-child(4)"} }, [RowSelector="tr"] ) in BoxOfficeTable
If this doesn’t pull the right data, use your browser’s developer tools (right-click the table on the site and select "Inspect") to find the correct CSS selectors for each column. Adjust the td:nth-child(n) values or use class names if the table has them.
3. Try the Web (Beta) Connector for Dynamic Content
If the table loads after JavaScript runs (common on modern sites), the standard "From Web" connector won’t catch it. Switch to the From Web (Beta) connector instead:
- Go to Get Data > From Web (Beta).
- Paste your URL and let the connector render the page like a real browser would.
- Once loaded, check the Navigator again—you might see the table listed now that all dynamic content is included.
Quick note: Always double-check Box Office Mojo’s terms of service to ensure you’re allowed to scrape and use their data for your purposes.
内容的提问来源于stack exchange,提问作者haoran zhang

