【问题标题】:Scrape entire scrolling-load page with Python Requests使用 Python 请求抓取整个滚动加载页面
【发布时间】:2017-09-04 00:58:57
【问题描述】:

具体来说,我正在尝试抓取整个页面,但只获取其中的一部分:

http://store.nike.com/us/en_us/pw/mens-shoes/7puZoi3?ipp=120

如果我使用:

 r= requests.get('http://store.nike.com/us/en_us/pw/mens-shoes/7puZoi3?ipp=120')

它只获取页面的“可见”部分,因为向下滚动时会加载更多项目

我知道 PyQT 中有一些解决方案,例如:

Repeatedly scroll to the bottom of a page using PyQt QWebKit

但是有没有办法让 python 请求不断滚动到网页底部,直到所有项目加载?

【问题讨论】:

    标签: python-2.7 python-requests


    【解决方案1】:

    您可以使用浏览器开发控制台(F12 - Chrome 中的网络)监控页面网络活动,以查看当您向下滚动时页面执行的请求、使用该数据并使用 requests 重现请求。作为替代方案,您可以使用selenium 以编程方式控制浏览器向下滚动直到页面结束,然后保存其 HTML。

    我想我找到了正确的请求

    Request URL:http://store.nike.com/html-services/gridwallData?country=US&lang_locale=en_US&gridwallPath=mens-shoes/7puZoi3&pn=3
    Request Method:GET
    Status Code:200 OK
    Remote Address:87.245.221.98:80
    

    请求标头

    Provisional headers are shown
    Accept:application/json, text/javascript, */*; q=0.01
    Referer:http://store.nike.com/us/en_us/pw/mens-shoes/7puZoi3?ipp=120
    User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    X-NewRelic-ID:VQYGVF5SCBAJVlFaAQIH
    X-Requested-With:XMLHttpRequest
    

    似乎查询参数pn 表示当前的“子页面”。但是您仍然需要正确理解响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多