【问题标题】:python selenium phantomjs execute_scriptpython selenium phantomjs 执行脚本
【发布时间】:2019-05-17 01:46:36
【问题描述】:

为什么使用phantomjs时会出错?

from selenium import webdriver
page_index = 1076
#driver = webdriver.Chrome() # no any errors.
driver = webdriver.PhantomJS() # will error.    
driver.get('https://www.nexusmods.com/mods/')    
driver.execute_script(f"window.RH_ModList.Send('page', '{page_index}');")

结果:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"errorMessage":"undefined is not an object (evaluating 'window.RH_ModList.Send')","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"118","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:57491","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"script\": \"window.RH_ModList.Send('page', '1076');\", \"args\": [], \"sessionId\": \"e7abf670-0132-11e9-ba9e-f19731f1c19f\"}","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/e7abf670-0132-11e9-ba9e-f19731f1c19f/execute"}}
Screenshot: available via screen

【问题讨论】:

    标签: python selenium selenium-webdriver phantomjs


    【解决方案1】:

    为什么使用phantomjs时会出错?

    这是因为 PhantomJS 不支持ES6 Promise See the issue in Github here。如果您进行调试,您将看到该页面的此错误

    ReferenceError: 找不到变量:Promise

    phantomjs://platform/bootstrap.js:87 2

    ReferenceError:找不到变量:$

    因为 PhantomJS 被遗弃,所以没有简单的修复。

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 2015-06-05
      • 2015-07-12
      • 1970-01-01
      • 2022-11-10
      • 2015-08-11
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      相关资源
      最近更新 更多