You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用IMPORTXML将<section id="data-container">内容导入Google Sheets?

How to Import Inc.com 5000 EU 2018 List into Google Sheets (Fixing IMPORTXML Issues)

Hey there, let's break down why your IMPORTXML formulas aren't working and how to fix this. First, let's address the XPath syntax errors, then tackle the bigger issue of dynamic content loading on that page.

1. Fixing Your XPath Syntax

Your original XPath expressions have small syntax mistakes that would prevent them from working even if the content was static:

  • Wrong: //section/[@id='data-container'] → The extra slash after section is invalid. It should be //section[@id='data-container'] (selects the <section> element with id="data-container").
  • Wrong: //section/*[@id='data-container'] → This looks for a child element of <section> with that id, but the data-container is the section itself, so the * is unnecessary.
  • Wrong: //section/data-container → This tries to select a <data-container> tag inside <section>, which doesn't exist—you need to use @id to target attributes.

The correct XPath to target that section would be:

//section[@id='data-container']

Or even simpler:

//*[@id='data-container']

But even with the right XPath, you still won't get the enterprise list—here's why.

2. The Real Issue: Dynamic Content Loading

The Inc.com 5000 EU list is loaded dynamically with JavaScript. When you use IMPORTXML, it only fetches the initial static HTML of the page, which doesn't include the actual enterprise data. The data is loaded later by the page's JavaScript code, so IMPORTXML can't see it.

YouTube tutorials for Wikipedia work because Wikipedia tables are in the static HTML—no JS needed to load them.

3. Solutions to Import the Data

Here are two reliable ways to get this data into Google Sheets:

Option 1: Use the Website's API (Easiest)

Most modern sites load dynamic data via an API. Here's how to find and use it:

  1. Open the Inc.com list page in Chrome, right-click → Inspect to open DevTools.
  2. Go to the Network tab, then refresh the page.
  3. Click the XHR filter to see only API requests.
  4. Look for requests that return JSON data with enterprise details (look for names like list, data, or inc5000).
  5. Once you find the correct API URL, copy it.
  6. In Google Sheets, use a custom function like IMPORTJSON (install it first via the Google Workspace Marketplace) to import the JSON data. For example:
    =IMPORTJSON("your-copied-api-url")
    
    This will pull the structured data directly into your sheet.

Option 2: Use Google Apps Script to Fetch Dynamic Content

If you can't find the API, you can use Google Apps Script to simulate loading the page (including executing JavaScript) and extract the data. Here's a basic template:

  1. Open your Google Sheet, go to Extensions → Apps Script.
  2. Replace the default code with this:
    function importInc5000EU() {
      // First, try to find the API URL as described above—this is faster than parsing HTML
      const apiUrl = "PASTE-THE-API-URL-YOU-FOUND-HERE";
      const response = UrlFetchApp.fetch(apiUrl);
      const data = JSON.parse(response.getContentText());
    
      // Get the active sheet
      const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      sheet.clear(); // Clear existing data
    
      // Write headers
      if (data.length > 0) {
        const headers = Object.keys(data[0]);
        sheet.getRange(1, 1, 1, headers.length).setValues([headers]);
    
        // Write rows of data
        const rows = data.map(item => headers.map(header => item[header] || ""));
        sheet.getRange(2, 1, rows.length, headers.length).setValues(rows);
      }
    }
    
  3. Paste the API URL you found into the apiUrl variable.
  4. Save the script, then run it (you'll need to grant permissions the first time).

Important Notes

  • Always check the site's Terms of Service before scraping or using their API—make sure you're allowed to import the data.
  • Avoid making too many rapid requests to the API, as this could get your IP blocked.
  • If the API requires authentication (unlikely for public lists), you might need to adjust the script to include headers from the DevTools request.

内容的提问来源于stack exchange,提问作者hccavs19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:50:15