gpt4 book ai didi

python selenium phantomjsexecute_script

转载 作者:行者123 更新时间:2023-12-01 01:21:23 25 4
gpt4 key购买 nike

为什么使用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

最佳答案

Why an error occurs when using phantomjs?

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

ReferenceError: Can't find variable: Promise

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

ReferenceError: Can't find variable: $

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

关于python selenium phantomjsexecute_script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53802586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com