Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.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 使用click()webdriver函数时超时_Python_Selenium_Web Scraping_Webdriver_Click - Fatal编程技术网

Python 使用click()webdriver函数时超时

Python 使用click()webdriver函数时超时,python,selenium,web-scraping,webdriver,click,Python,Selenium,Web Scraping,Webdriver,Click,这是我的第一个网页抓取项目,我将SeleniumWebDriver与Python结合使用,以便在选择网站上的一些选项后动态生成一些csv文件(尽管我还没有) 但是,当执行到达一个按钮click()时,我面临一个意外的超时。执行了单击,但它卡在那里,直到超时才继续执行 关于如何解决这个问题有什么线索吗 谢谢 from selenium import webdriver from selenium.webdriver.support.ui import Select import time dr

这是我的第一个网页抓取项目,我将SeleniumWebDriver与Python结合使用,以便在选择网站上的一些选项后动态生成一些csv文件(尽管我还没有)

但是,当执行到达一个按钮click()时,我面临一个意外的超时。执行了单击,但它卡在那里,直到超时才继续执行

关于如何解决这个问题有什么线索吗

谢谢

from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time


driver = webdriver.Firefox()
driver.get('http://www8.receita.fazenda.gov.br/SimplesNacional/Aplicacoes/ATBHE/estatisticasSinac.app/Default.aspx')
driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_lnkOptantesPorCNAE').click()
Select(driver.find_element_by_id("ctl00_ctl00_Conteudo_AntesTabela_ddlColuna")).select_by_visible_text("Município")
filtro_uf =     driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_btnFiltros')

for i in range (1, 28):
    filtro_uf.click()
    uf = Select(driver.find_element_by_id("ctl00_ctl00_Conteudo_AposTabela_ddlUf"))
    uf.options[i].click()
    time.sleep(2)
    driver.find_element_by_id('chkTodosMunicipios').click()
    time.sleep(2)
    driver.find_element_by_xpath("//*[contains(text(),'Ok')]").click()
    time.sleep(2)

# Here is where my code get stuck and gets a timeout
    driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_btnExibir').click()
我得到的错误是:

Traceback (most recent call last):      
File "/home/hissashi/Desktop/Python3/WS_SINAC/download_SINAC.py", line 22, in <module>   driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_btnExibir').click()   
  File "/home/hissashi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)    
  File "/home/hissashi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 501, in _execute
    return self._parent.execute(command, params)   
  File "/home/hissashi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)   
  File "/home/hissashi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response   
raise exception_class(message, screen, stacktrace)
**selenium.common.exceptions.TimeoutException: Message: Timeout loading page after 300000ms**
回溯(最近一次呼叫最后一次):
文件“/home/hissashi/Desktop/Python3/WS_SINAC/download_SINAC.py”,第22行,在驱动程序中。按id(“ctl00_ctl00_Conteudo_AntesTabela_btnExibir”)查找元素。单击()
文件“/home/hissashi/.local/lib/python3.5/site packages/selenium/webdriver/remote/webelement.py”,第80行,单击
self.\u执行(命令。单击\u元素)
文件“/home/hissashi/.local/lib/python3.5/site packages/selenium/webdriver/remote/webelement.py”,第501行,在
返回self.\u parent.execute(命令,参数)
文件“/home/hissashi/.local/lib/python3.5/site packages/selenium/webdriver/remote/webdriver.py”,执行中的第308行
self.error\u handler.check\u响应(响应)
文件“/home/hissashi/.local/lib/python3.5/site packages/selenium/webdriver/remote/errorhandler.py”,第194行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
**selenium.common.Exception.TimeoutException:消息:3000000毫秒后加载页面超时**

我找到了解决这个问题的方法

显然,click()函数会阻止代码,直到页面“完全”加载。然而,由于某些原因,页面一直在加载(没有任何其他东西可以加载),它会一直保存我的代码,直到达到超时限制为止

我没有使用click,而是将其改为key-ENTER,页面仍然会一直加载,但不再保存代码

#FROM CLICK
driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_btnExibir').click()

#TO SENDING ENTER (ue007)
driver.find_element_by_id('ctl00_ctl00_Conteudo_AntesTabela_btnExibir').send_keys(u'\ue007') 

filter\u uf.click()
是否加载任何页面?它加载一种“弹出窗口”,但第一页仍在其后面。在弹出窗口上选择筛选选项并单击“确定”按钮后,弹出窗口将关闭,并再次显示其后面的主页面。执行最后一次click(),显示一个数据表,该数据表应该是这样的,但即使在该表完全生成之后,页面仍会保持加载状态,就好像它仍在加载某个内容,但实际上并非如此。下一次迭代不会开始,因为加载一直持续到超时。