首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用requests html python库,如何滚动?到页末

使用requests html python库,如何滚动?到页末
EN

Stack Overflow用户
提问于 2020-05-15 18:16:57
回答 1查看 313关注 0票数 0

问题是,我需要抓取数据,但只有在滚动时才会生成整个数据。

如果我在滚动之前进行抓取,那么只有部分数据会被抓取,而不是全部。

代码语言:javascript
复制
from requests_html import AsyncHTMLSession

link="https://www.daraz.com.np/catalog/?q={}"
asession = AsyncHTMLSession()
async def get_daraz():
    r = await asession.get(link.format("mouse"))
    await r.html.arender()
    return r.html
results = asession.run(get_daraz)


items_div=results[0].xpath('//*[@id="root"]/div/div[2]/div[1]/div/div[1]/div[2]/div')

for item in items_div:
    print(item.xpath('//div/div/div[1]/div/a/img',first=True))

上面只给出了前三张图片。

EN

回答 1

Stack Overflow用户

发布于 2020-05-15 18:34:56

您可以查看pyautogui库来滚动网页。Selenium也有效,但被许多网站屏蔽。

代码语言:javascript
复制
pyautogui.moveTo(200,200) # move mouse to a blank spot on the screen. (x, y) coordinates.
pyautogui.click(200,200) # click spot on screen at the coordinates of your choice.
pyautogui.scroll(100) # you could use a higher number to scroll more to load the whole page.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61816900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档