无法在单击JavaScript上执行硒 - python
Unable to execute onClick javascript selenium - python
我正在尝试从TripAdvisor中抓取一些数据,并使用Python
绑定的Selenium
来完成它。
网页中的审阅对象有时在底部有一个"更多"按钮,以便在单击它时显示完整的审阅内容。它实际上是一个 span 元素,带有为其编写的 onlclick JS 函数。
我想要实现的是加载页面,找到"更多"链接并单击它们,以便在抓取操作开始之前显示网页完全加载的评论。
到目前为止,我已经尝试了以下代码,但没有运气。我似乎无法理解堆栈跟踪中显示的错误。
import os
import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.tripadvisor.ca/Attraction_Review-g304138-d317476-Reviews-Temple_of_the_Tooth_Sri_Dalada_Maligawa-Kandy_Central_Province.html#REVIEWS");
more = [];
more = driver.find_elements_by_class_name('moreLink')
print(len(more));
for x in range(0,len(more)):
if more[x].is_displayed():
more[x].click();
print("clicked");
这些是我在控制台中收到的错误日志。
3
Traceback (most recent call last):
File "C:'Users'**'workspace'ReviewScraper'src'scraper'test3.py", line 13, in <module>
more[x].click();
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'site-packages'selenium'webdriver'remote'webelement.py", line 75, in click
self._execute(Command.CLICK_ELEMENT)
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'site-packages'selenium'webdriver'remote'webelement.py", line 454, in _execute
return self._parent.execute(command, params)
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'site-packages'selenium'webdriver'remote'webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'site-packages'selenium'webdriver'remote'errorhandler.py", line 102, in check_response
value = json.loads(value_json)
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'json'__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'json'decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:'Users'**'AppData'Local'Programs'Python'Python35-32'lib'json'decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
任何帮助都非常感谢。
我设法通过恢复到 Selenium 1.48.0 并在每次抓取评论之前登录 TA 来完成这项工作。登录后,您可以单击"更多"按钮并轻松提取完整的评论。
相关文章:
- 在selenium python中执行脚本
- 在引导程序中从 HTML 表单执行 Python (CGI) 文件.带有Apache Server的JS
- 在python中使用Selenium执行Javascript(Tkinter作为GUI)
- 在 Python 中使用 Selenium 执行 JavaScript 后存储结果
- 我无法从 PHP 执行 pdf 生成 python 命令
- 这是否可以在使用 python 执行 javascript 后加载页面
- 创建一个超链接(或按钮),用于执行 python 脚本,然后在脚本完成时重定向
- 从 Python 执行提示符 Javascript
- 在满足条件时在python中执行javascript
- 在纯 Python 环境中执行 JavaScript
- Javascript执行python文件
- 如何在Javascript中执行python zip()
- 按钮执行python脚本,使用jquery
- 如何在splunk中从javascript执行python脚本
- jQuery加载img,同时执行Python脚本PHP
- 加载网页时执行Python脚本
- 在用户的计算机上执行python脚本并检索输出
- 在按钮单击时执行python脚本
- 在节点应用程序中执行python脚本
- 如何在本地机器上从网页执行Python和.bat脚本