我正在嘗試從一個名為Correios的網(wǎng)站獲取所有數(shù)據(jù),在此網(wǎng)站中,我需要處理一些下拉菜單,這些菜單出現(xiàn)一些問題,例如:它無法從第一個下拉框信息中獲取所有值。from selenium import webdriverfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support.select import Selectchrome_path = r"C:\\Users\\Gustavo\\Desktop\\geckodriver\\chromedriver.exe"driver = webdriver.Chrome(chrome_path)lista_x = []driver.get("http://www2.correios.com.br/sistemas/agencias/")driver.maximize_window()estado_select = Select(driver.find_element_by_id('estadoAgencia'))WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'municipioAgencia')))municipio_select = Select(driver.find_element_by_id('municipioAgencia'))for opt in estado_select.options: print(opt.get_attribute('innerHTML')) opt.click() for opt2 in municipio_select.options: print(opt.get_attribute('innerHTML')) opt2.click()driver.close()有時我的代碼運行正常,但有時卻出現(xiàn)此錯誤:ACREACREALAGOASALAGOASTraceback (most recent call last): File "C:\Users\Gustavo\Desktop\insper\trabalho\Correios3.py", line 23, in <module> opt2.click() File "C:\Users\Gustavo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\Gustavo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute return self._parent.execute(command, params) File "C:\Users\Gustavo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute self.error_handler.check_response(response) File "C:\Users\Gustavo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)我應(yīng)該怎么辦?
添加回答
舉報
0/150
提交
取消