Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法执行onClick javascript selenium-python_Javascript_Python_Html_Selenium_Selenium Webdriver - Fatal编程技术网

无法执行onClick javascript selenium-python

无法执行onClick javascript selenium-python,javascript,python,html,selenium,selenium-webdriver,Javascript,Python,Html,Selenium,Selenium Webdriver,我试图从TripAdvisor中获取一些数据,并使用Selenium和Python绑定来完成 网页中的审阅对象有时在底部有一个“More”按钮,单击该按钮可显示完整的审阅内容。它实际上是一个span元素,为它编写了一个onclick JS函数 我想要实现的是加载页面,找到“更多”链接并单击它们,这样网页就可以在开始抓取操作之前完全加载所显示的评论 到目前为止,我已经尝试了以下代码,但没有成功。我似乎无法理解堆栈跟踪中显示的错误 import os import time from seleniu

我试图从TripAdvisor中获取一些数据,并使用
Selenium
Python
绑定来完成

网页中的审阅对象有时在底部有一个“More”按钮,单击该按钮可显示完整的审阅内容。它实际上是一个span元素,为它编写了一个onclick 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)
3
回溯(最近一次呼叫最后一次):
文件“C:\Users\**\workspace\ReviewScraper\src\scraper\test3.py”,第13行,在
更多[x]。单击();
文件“C:\Users\**\AppData\Local\Programs\Python35-32\lib\site packages\selenium\webdriver\remote\webelement.py”,第75行,单击
self.\u执行(命令。单击\u元素)
文件“C:\Users\**\AppData\Local\Programs\Python\Python35-32\lib\site packages\selenium\webdriver\remote\webelement.py”,第454行,在执行
返回self.\u parent.execute(命令,参数)
文件“C:\Users\**\AppData\Local\Programs\Python\Python35-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第201行
self.error\u handler.check\u响应(响应)
文件“C:\Users\**\AppData\Local\Programs\Python\35-32\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第102行,在check\u响应中
value=json.load(value\u json)
文件“C:\Users\**\AppData\Local\Programs\Python35-32\lib\json\\uuuu init\uuuuu.py”,第319行,加载
返回\u默认\u解码器。解码
文件“C:\Users\**\AppData\Local\Programs\Python35-32\lib\json\decoder.py”,第339行,在decode中
obj,end=self.raw\u decode(s,idx=\u w(s,0.end())
文件“C:\Users\**\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py”,第357行,原始解码
从None引发JSONDecodeError(“预期值”,s,err.value)
json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)

非常感谢您提供的任何帮助。

我通过恢复到Selenium 1.48.0并在每次删除评论之前登录TA,成功地完成了这项工作。登录后,您可以单击“更多”按钮,轻松提取完整评论