问题是,我需要抓取数据,但只有在滚动时才会生成整个数据。
如果我在滚动之前进行抓取,那么只有部分数据会被抓取,而不是全部。
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))上面只给出了前三张图片。
发布于 2020-05-15 18:34:56
您可以查看pyautogui库来滚动网页。Selenium也有效,但被许多网站屏蔽。
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.https://stackoverflow.com/questions/61816900
复制相似问题