【问题标题】:Web Crawling Using Python Request with Cookies Enabled使用启用了 Cookie 的 Python 请求进行 Web 爬网
【发布时间】:2019-08-17 23:12:49
【问题描述】:

我正在尝试抓取此特定网页: https://www.grainger.com/category/abrasives/abrasive-blasting/abrasive-blasting-cabinets

使用以下代码行:

page = requests.get("https://www.grainger.com/category/abrasives/abrasive-blasting/abrasive-blasting-cabinets")

但是,该页面带有默认的“表格”视图。但是我要抓取的网页是启用“列表视图”的情况下。如何请求启用“列表”视图的网页,如下图所示:

【问题讨论】:

    标签: python beautifulsoup request web-crawler


    【解决方案1】:

    通过谷歌浏览器的网络标签,在我看来,这个网站通过设置 cookie 知道显示哪个视图,所以如果你想以列表的形式查看,你可以在请求中设置这个 cookie。

    requests.get("https://www.grainger.com/category/abrasives/abrasive-blasting/abrasive-blasting-cabinets", cookies={'pv':'list'})
    

    以后您可以查看this reference,以帮助您了解浏览时实际发生的情况。

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多