【问题标题】:Python click Js link with seleniumPython单击带有硒的Js链接
【发布时间】:2023-03-07 08:22:01
【问题描述】:

我已测试网页抓取:http://www.guiadosquadrinhos.com/todas-capas-disponiveis

我需要在分页中导航以获取收藏的信息页面。 我需要点击链接 javascript 下一页:

javascript:__doPostBack('ctl00$MainContent$lstProfileView$dataPagerNumeric2$ctl02$ctl00')

from selenium import webdriver
import time

driver = webdriver.PhantomJS(executable_path='C:\Python27\Tools\phantomjs\phantomjs.exe')
driver.get("http://www.guiadosquadrinhos.com/todas-capas-disponiveis")
#print(driver.find_elements_by_class_name("numero_capinha")[0].text)
#driver.find_elements_by_class_name("next_last")[0].click()
#time.sleep(5)
print(driver.find_elements_by_class_name("numero_capinha")[0].text)
driver.find_elements_by_class_name("next_last")[0].click()
print(driver.find_elements_by_class_name("numero_capinha")[0].text)

我的代码返回:

sobreontem - 独立

Traceback(最近一次调用最后一次):文件“teste_selenium.py”,第 10 行,在 driver.find_elements_by_class_name("next_last")[0].click() 文件 "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", 第 74 行,点击 self._execute(Command.CLICK_ELEMENT) 文件 "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", 第 453 行,在 _execute return self._parent.execute(command, params) 文件 "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", 第 201 行,在执行中 self.error_handler.check_response(response) 文件 "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", 第 181 行,在 check_response 中 raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotVisibleException: 消息: {"errorMessage":"元素当前不可见,可能不可见 操纵","请求":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"81" ,"Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:63160","User-Agent":"Python-urllib/2.7"},"httpVersion": "1.1","方法":"POST","post":"{\"sessionId\": \"5d3cfdc0-5d3b-11e5-b784-67706273a0bb\", \"id\": \":wdc:1442494581220\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory" :"/","path":"/click","re​​lative":"/click","port":"","host":"","password":"","user":"" ,"userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]}," urlOriginal":"/session/5d3cfdc0-5d3b-11e5-b784-67706273a0bb/element/%3Awdc%3A1442494581220/click"}} 屏幕截图:可通过屏幕获取

有什么问题?

【问题讨论】:

  • 请张贴相关next_last元素的html。它似乎目前在文本页面上不可见,您必须执行一些 javascript 才能使其可见。
  • >

标签: python web-scraping


【解决方案1】:

既然,你正在做以下 -

driver.find_elements_by_class_name("next_last")[0].click()

如果您查看源代码,则有多个具有此类名称的元素,第一个被禁用,因为这是上一个按钮,您在第一页。

【讨论】:

  • 是真的!谢谢,解决了我的问题,解决了这个代码:driver.find_elements_by_class_name("next_last")[2].click()
猜你喜欢
  • 2013-09-07
  • 1970-01-01
  • 2013-11-05
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多