【发布时间】:2016-04-24 03:18:51
【问题描述】:
我正在尝试从 TripAdvisor 抓取一些数据并使用 Selenium 和 Python 绑定来完成它。
网页中的评论对象有时在底部有一个“更多”按钮,点击后会显示完整的评论内容。它实际上是一个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)
非常感谢任何帮助。
【问题讨论】:
标签: javascript python html selenium selenium-webdriver