gpt4 book ai didi

python - 在 Python 中使用 Selenium 和 PhantomJS 时出现异常错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:30 25 4
gpt4 key购买 nike

我正在尝试填写 these page 的表格,我检查了 HTML 代码和我正在寻找的表单,但是当我运行我的代码时,我收到了一个在 selenium 中从未见过的错误。

我在 Python 3.6.1 中使用 PhantomJS 2.1.1 和 Selenium。

我想填写这些表格。

<input type="text" name="Dt_Ref" value="31/08/2017" maxlength="10" size="10" class="form_data" onBlur="formatCamp(this, 'date');javascript:if(REUNE.Dt_Ref.value!=REUNE.Dt_RefAnt.value){REUNE.target='_self';REUNE.action='reune.asp';REUNE.submit()};" onKeyPress="return(validaConteudo(event, this, 'date'))" onKeyUp="saltaCampo(event, this, 'date',8)" onFocus="removeCaracs(this, 'date')">  <a style="cursor:hand; cursor:pointer;" onclick="openCalendar(document.REUNE.elements['Dt_Ref']);return false;">

我的代码是:

from selenium import webdriver


url = 'http://www.anbima.com.br/reune/reune.asp'
path_phantom = 'C:\\Users\\TBMEPYG\\AppData\\Local\\Continuum\\Anaconda3\\Lib\\site-packages\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'

#Processing

driver = webdriver.PhantomJS(executable_path= path_phantom)
driver.get(url)
name = driver.find_element_by_name("Dt_Ref")
driver.quit()

我得到了这个错误:

Traceback (most recent call last):
File "C:\Users\TBMEPYG\Desktop\beta_anbima.py", line 11, in <module>
name = driver.find_element_by_name("Dt_Ref")
File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 426, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 832, in find_element
'value': value})['value']
File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Users\TBMEPYG\AppData\Local\Continuum\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"89","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:64945","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"name\", \"value\": \"Dt_Ref\", \"sessionId\": \"cc170460-8e5e-11e7-ad22-8d3d940cf70e\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/cc170460-8e5e-11e7-ad22-8d3d940cf70e/element"}}
Screenshot: available via screen

这是我的代码的第一步。我有银行代理,这可能就是问题所在。当我从 Chrome 访问时,该页面工作正常。当我尝试在 this site 中使用相同的代码(更改 url 和元素名称)时,效果很好。

谢谢大家。

最佳答案

这是 PhantomJS 的问题/错误。

我建议您使用 Chrome 本身或用于 selenium/standalone-chrome 的 docker 镜像

如果你看https://github.com/ariya/phantomjs/issues1923 个 Unresolved 问题,这是不言而喻的。

你甚至无法查询

driver.find_elements_by_xpath("//*")

你会得到错误

NoSuchElementException: Message: {"request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"87","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:53425","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"xpath\", \"value\": \"//*\", \"sessionId\": \"eb09e680-8e72-11e7-8b72-d1137b47fa59\"}","url":"/elements","urlParsed":{"anchor":"","query":"","file":"elements","directory":"/","path":"/elements","relative":"/elements","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/elements","queryKey":{},"chunks":["elements"]},"urlOriginal":"/session/eb09e680-8e72-11e7-8b72-d1137b47fa59/elements"}}
Screenshot: available via screen

所以打开一个错误并计数1924,但我真的怀疑你会得到太多帮助

关于python - 在 Python 中使用 Selenium 和 PhantomJS 时出现异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45984971/

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