You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何用ImportXML/ImportHTML自动获取YouTube订阅数至谷歌表格?

How to Pull YouTube Subscriber Counts into Google Sheets with IMPORTXML/IMPORTHTML

Absolutely! You can use IMPORTXML (the better fit here) to automate YouTube subscriber count updates in Google Sheets—no more manual data entry. The most common roadblock here is YouTube’s frequently updated page structure, which is likely why your initial attempts failed. Let’s break down a reliable approach:

Why IMPORTXML Over IMPORTHTML?

IMPORTHTML is designed for pulling tables or lists from websites, but YouTube subscriber counts aren’t stored in structured tables. IMPORTXML is built to extract data via XPath, which is perfect for targeting specific UI elements like subscriber numbers.

Step 1: Grab the Correct XPath for Subscriber Counts

YouTube’s UI changes regularly, so you’ll need to fetch a fresh XPath for each channel:

  1. Open the target YouTube channel page (e.g., https://www.youtube.com/@MrBeast).
  2. Right-click the subscriber count text (e.g., "200M subscribers") and select Inspect to open your browser’s DevTools.
  3. In the Elements panel, you’ll see the element holding the subscriber count—it usually looks like this:
    <yt-formatted-string id="subscriber-count" class="style-scope ytd-channel-subscription-button-renderer">200M subscribers</yt-formatted-string>
    
  4. Right-click this element, hover over Copy, then select Copy XPath.

Step 2: Build Your Google Sheets Formula

Paste the copied XPath into an IMPORTXML formula. For example:

=IMPORTXML("https://www.youtube.com/@MrBeast", "//*[@id='subscriber-count']")

This will pull the full formatted string (like "200M subscribers"). If you only want the numeric value (without the "subscribers" label), clean it up with REGEXEXTRACT:

=REGEXEXTRACT(IMPORTXML("https://www.youtube.com/@MrBeast", "//*[@id='subscriber-count']"), "\d+\.*\d*[KMB]?")

This regex extracts just the number (e.g., "200M") for cleaner data.

Common Fixes for Failed Imports

  • Outdated XPath: YouTube updates its UI often, so if your formula returns an error, repeat Step 1 to get a new XPath.
  • Hidden Subscriber Counts: If the channel has hidden their subscriber count, this method won’t work—publicly unavailable data can’t be pulled via these functions.
  • Request Limits: Google Sheets restricts how often IMPORTXML can fetch data. If you’re pulling counts for dozens of channels, you might hit temporary restrictions.

Bonus: More Reliable Alternative (YouTube Data API)

If you want a solution that won’t break when YouTube updates its UI, use the YouTube Data API. You’ll need an API key, but it lets you pull structured, consistent subscriber data. You can even use Google Apps Script to automate populating your sheet with API data—though this is a bit more advanced.

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

火山引擎 最新活动