Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 硒/幻影罐头';无法获取url-随机失败_Python_Selenium_Selenium Webdriver_Web Scraping_Phantomjs - Fatal编程技术网

Python 硒/幻影罐头';无法获取url-随机失败

Python 硒/幻影罐头';无法获取url-随机失败,python,selenium,selenium-webdriver,web-scraping,phantomjs,Python,Selenium,Selenium Webdriver,Web Scraping,Phantomjs,我正在使用python和Selenium和phantomJS对网站进行爬网。 beautifulsou解析一些html。 一切正常,但我遇到了随机故障,脚本在下面的while循环中被阻塞,该循环启动webdriver并获取url内容 while (htmlContent is None) : try: driver = webdriver.PhantomJS() driver.implicitly_wait(20) driver.get(u

我正在使用python和
Selenium
phantomJS
对网站进行爬网。
beautifulsou
解析一些html。
一切正常,但我遇到了随机故障,脚本在下面的while循环中被阻塞,该循环启动webdriver并获取url内容

while (htmlContent is None) :
    try:
        driver = webdriver.PhantomJS()
        driver.implicitly_wait(20)
        driver.get(url)
        driver.implicitly_wait(20)
        soup = BeautifulSoup(driver.page_source , 'html.parser')
        htmlContent = soup.find("table", class_="desc-item")
        driver.close()
    except:
  • 我在这个特定的url上重试(重新启动python脚本) 脚本失败的地方-->它正在工作
  • 如果我设置了超时异常,脚本将继续正确地刮取其他URL,但在其他URL上随机失败
我没有主意了-有什么建议吗?
谢谢

删除try/except块,让它失败并发布您看到的异常。谢谢。驱动程序。隐式地等待(20)#只使用一次,不需要第二次。用-->捕获异常,异常除外为e:并打印(str(e))