【问题标题】:Setting a User Agent in scrape-it在 scrape-it 中设置用户代理
【发布时间】:2021-02-13 20:15:43
【问题描述】:

我在我的 node.js 抓取工具中使用scrape-it(用于识别正确的关键字使用)但被某些网站识别为机器人并且没有获取任何内容。有没有办法为 GET 请求配置一个已知的 user agent 标头以绕过阻止?

【问题讨论】:

    标签: node.js web-scraping user-agent


    【解决方案1】:

    您可以通过将选项对象传递给 scrape-it 来设置标头,包括 User-agent:

    scrapeIt({
        url: "http://example.com"
      , headers: { "User-agent": "known-user-agent-of-choice" }
    },
    {
      // some scrapeHTML options ...
    })
    .then(
     // some code ...
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 2012-05-02
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多