報錯python
Traceback (most recent call last): File "C:/myFiles/code/cnki/cnki_1/core/knavi.py", line 281, in <module> main() File "C:/myFiles/code/cnki/cnki_1/core/knavi.py", line 270, in main periodical(driver, i["periodical_herf"]) File "C:/myFiles/code/cnki/cnki_1/core/knavi.py", line 232, in periodical driver.get(URL) # 獲取頁面 File "C:\python3.6.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get self.execute(Command.GET, {'url': url}) File "C:\python3.6.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\python3.6.3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 241, in check_response raise exception_class(message, screen, stacktrace, alert_text) selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None Message: unexpected alert open: {Alert text : 您點擊的頻率過快!請稍後再試} (Session info: chrome=73.0.3683.103) (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.15063 x86_64)
解決方案:web
from selenium.common.exceptions import UnexpectedAlertPresentException except UnexpectedAlertPresentException: driver.switch_to.alert.accept() driver.delete_all_cookies() time.sleep(300) continue