selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None;Message: unexpected alert open: {Alert text : 您点击的频率过快!请稍后再试}

报错

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)

 

解决方案:

from selenium.common.exceptions import UnexpectedAlertPresentException


            except UnexpectedAlertPresentException:
                driver.switch_to.alert.accept()
                driver.delete_all_cookies()
                time.sleep(300)
                continue

 

posted @ 2019-04-19 11:18  我当道士那儿些年  阅读(5326)  评论(0编辑  收藏  举报