我正在尝试使用无头 Selenium 抓取包含图像的网站。最初,该网站填充了 50 张图像。如果向下滚动,就会加载越来越多的图像。
Windows 7 x64
python 2.7
最近安装的 selenium
[1] 非无头
导航到带有 selenium 的网站如下:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(url)
browser.execute_script('window.scrollBy(0, 10000)')
browser.page_source
这有效(如果有人有更好的建议,请告诉我)。
我可以继续scrollBy()直到我到达最后,然后拉出源页面。
[2] 使用 HTMLUNIT 无头
from selenium import webdriver
driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
driver.get(url)
我不能在这种无头环境中使用scrollBy() 。
有关如何抓取此类页面的任何建议?谢谢