Selenium phantomjs webdriver在点击时挂起

时间:2016-09-22 13:07:45

标签: python selenium phantomjs

我正在尝试通过单击下一步按钮浏览页面。它适用于前两个三页,之后它只是在点击时挂起。

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ('Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.89 Safari/537.36')
driver = webdriver.PhantomJS("path to phantomjs",desired_capabilities=dcap)
driver.get("http://www.zappos.com/product/review/7391917/page/1/start/5")

print driver.current_url
for i in range(5):
    print i
    driver.find_element_by_css_selector("p[class='top-pagination'] a[class*='next']").click()
    time.sleep(3)
    print driver.current_url

以下是输出,显示前几页发生的点击以及生成的URL更改。但它在无限期的几次点击之后就会挂起。

http://www.zappos.com/product/review/7391917/page/1/start/5
0
http://www.zappos.com/product/review/7391917/page/2/start/5
1
http://www.zappos.com/product/review/7391917/page/3/start/5
2

有关它为何会发生的任何想法吗?

0 个答案:

没有答案