Selenium不会在页面

时间:2017-11-19 21:29:23

标签: python selenium phantomjs

我正在使用Selenium(使用python)定期监控页面并保存屏幕截图。这是在树莓派(armv6)上完成的。因此,我正在使用PhantomJS。

我正在监控某些元素,因为树莓派不是最快的,我正在执行一个带driver.execute_script的脚本来缩小页面,使截图不会太大。

不幸的是,在执行此脚本时,会引发以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "`**path**`/bot.py", line 39, in __init__
    self.graphs(self.threads['graphs'])
  File "`**path**`/bot.py", line 93, in graphs
    self.driver.execute_script(`**script**`)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 543, in execute_script
    'args': converted_args})['value']
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' *.google-analytics.com\".\n","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"716","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:46451","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"script\": `**script**`, \"args\": [], \"sessionId\": \"69182660-cd69-11e7-b52d-9131a53fa749\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/69182660-cd69-11e7-b52d-9131a53fa749/execute"}}
Screenshot: available via screen

我用谷歌搜索了这个错误,但我找不到解决方案。这个Selenium是阻止我执行这个脚本还是PhantomJS?

谢谢!

[编辑] 这是初始化selenium webdriver的代码:

def __init__(self):
    self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false'])
    self.driver.set_window_size(1070, 800)

    self.threads = {'check_login': threading.Event(), 'graphs': threading.Event()}

    self.login()

    self.graphs(self.threads['graphs'])
    self.check_login(self.threads['check_login'])

0 个答案:

没有答案