【发布时间】:2015-08-02 02:32:17
【问题描述】:
我正在尝试获取页面上的所有元素,但它具有无限滚动。我尝试向下滚动页面,然后获取属性,但它没有把它们全部捡起来?出于某种原因,我只得到了大约一半?
driver = webdriver.Firefox()
driver.get("http://www.amazon.com/gp/pdp/profile/A2A46BUQRGSAB0/ref=cm_cr_dp_pdp")
lastHeight = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3)
newHeight = driver.execute_script("return document.body.scrollHeight")
print newHeight, lastHeight
if newHeight == lastHeight:
break
lastHeight = newHeight
tree = etree.HTML(driver.page_source)
product = tree.xpath('//span[@class="a-size-base product-title pr-multiline-ellipses-container"]//text()')[::3]
print len(product)
【问题讨论】:
-
我想查看是否有人评论了我列表中的特定产品。所以我只是想在配置文件上获取产品名称。 @birthofearth