我是新来的漂亮组合。我正在尝试从https://indianrecipes.com/new_and_popular中获取所有的食物配方和链接以及配料 问题是这个网站只会在向下滚动时加载更多的食物。我提到过这个问题,但没能充分利用。 我检查了inspect元素中的network选项卡,发现每次向下滚动时,都会发送一个XHR请求
api?tm=1565542062069
api?tm=1565542065302
api?tm=1565542073116
api?tm=1565542075617
有没有可能在python中模拟这样的请求,从该页面提取所有的食物配方?在
api?tm=1565542075617
中的数字是以毫秒为单位的epoch时间戳。对于请求,这可能不是必需的。在重要的是要查看服务器将响应请求发送到哪些数据。在XHR请求中,向下滚动到
Request Payload
以查看有效负载。在下面是一个Python代码,它在初始的
offset
个配方之后加载recipes_per_page
个配方。在我制作了一个简单的脚本,在这个脚本中,您可以指定每页的食谱数量和您要刮取的页数。它以JSON格式返回数据:
印刷品:
^{pr2}$你必须使用selenium将javascript从网页加载到html 然后使用selenium的滚动代码
然后使用beauthousoup从
soup = BeautifulSoup(driver.page_source, 'lxml')
相关问题 更多 >
编程相关推荐