【问题标题】:Node puppeteer scraping YouTube and encountering redirected you too many timesNode puppeteer 抓取 YouTube 并遇到重定向你太多次
【发布时间】:2022-02-16 16:29:26
【问题描述】:

我正在尝试使用 Node / puppeteer 抓取 YouTube 播放列表 URL。它工作正常,但现在我收到 ERR_TOO_MANY_REDIRECTS 错误。我仍然可以使用桌面上的 chrome 访问该页面。

我尝试过使用 chromium 浏览器和 chrome 浏览器。我也尝试过使用 puppeteer-extra 隐形插件和 random-useragent。

这就是我的代码目前的状态:

const browser = await puppeteer.launch({
      stealth: true,
      headless: false // true,
      executablePath: "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
      args: [
          '--disable-notifications', '--disable-features=site-per-process'
      ],
      defaultViewport: null
        });
      const page = await browser.newPage()
      await page.setUserAgent(random_useragent.getRandom());
      await page.goto(<playlist-url, {
        waitUntil: 'networkidle2',
        timeout: 0
      })


     await page.waitForSelector('button[aria-label="Agree to the use of cookies and other data for the purposes described"')

它在 page.goto 它炸弹。即使我尝试去https://www.youtube.com,它也会发生。

任何建议我接下来应该尝试什么。我尝试了代理服务器,但无法正常工作。我怀疑我需要一个代理来实际路由。

【问题讨论】:

  • 有趣的案例。即使没有无头运行,您也会收到此错误?尽量不要使用随机用户代理,可能会发生移动用户代理,而 Youtube 可能希望将您重定向到该网站的移动版本。另外,如果您尝试将现有帐户与 cookie 和 localstorage 等一起使用怎么办 - 请参阅 userDataDir here
  • 顺便说一句,使用 RSS 抓取播放列表可能更容易:youtube.com/feeds/videos.xml?playlist_id=PLAYLIST_ID
  • 抱歉耽搁了。你让我回答。我需要获取给定频道的实际播放列表 ID,所以我使用了youtube.com/feeds/videos.xml?channel_id=<Channel ID> 不错的一个。谢谢你的帮助。如果您将此作为答案发布,我会相应地标记它。
  • 很高兴我能提供帮助。关于答案的好主意,完成!

标签: node.js web-scraping youtube puppeteer


【解决方案1】:

如果您只需要给定频道的播放列表 ID,则可以在以下位置查询供稿:

https://youtube.com/feeds/videos.xml?channel_id=<Channel ID>

要获取视频的 ID,您可以在以下位置查询供稿:

https://youtube.com/feeds/videos.xml?playlist_id=PLAYLIST_ID 

【讨论】:

    猜你喜欢
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多