Python 使用硒刮除Tripadvisor的问题

Python 使用硒刮除Tripadvisor的问题,python,selenium,web-scraping,tripadvisor,Python,Selenium,Web Scraping,Tripadvisor,我有这个Python代码用于抓取TripAdvisor网站,直到去年(18天前),代码工作得非常棒,但现在代码不能正常工作,我得到了这个结果(如上所示) 我尝试过这样的更改container=driver.find_elements\u by_xpath(“//div[@class='data-test-target']) 但是不要工作。另外,我注意到现在网站没有元素taLnk-ulBlueLinks或元素review-container 请,如果你能帮助我的代码,这将是美妙的 PD:还有,我试

我有这个Python代码用于抓取TripAdvisor网站,直到去年(18天前),代码工作得非常棒,但现在代码不能正常工作,我得到了这个结果(如上所示)

我尝试过这样的更改
container=driver.find_elements\u by_xpath(“//div[@class='data-test-target'])
但是不要工作。另外,我注意到现在网站没有元素
taLnk-ulBlueLinks
或元素
review-container

请,如果你能帮助我的代码,这将是美妙的

PD:还有,我试着用漂亮的汤,但代码还是不行


结果是

    Traceback (most recent call last):
  File "gh_code2.py", line 63, in <module>
    driver.find_element_by_xpath('//a[@class="nav next taLnk ui_button primary"]').click()
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class="nav next taLnk ui_button primary"]"}
  (Session info: chrome=79.0.3945.117)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gh_code2.py", line 69, in <module>
    driver.find_element_by_xpath('//a[@class="nav next taLnk ui_button primary"]').click()
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File ".\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class="nav next taLnk ui_button primary"]"}
  (Session info: chrome=79.0.3945.117)
回溯(最近一次呼叫最后一次):
文件“gh_code2.py”,第63行,在
驱动程序。通过xpath(“//a[@class=“nav next taLnk ui_button primary”]”查找元素。单击()
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,第394行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,第978行,在find\u元素中
'value':value})['value']
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“xpath”,“选择器”:”//a[@class=“nav next taLnk ui_button primary”]”
(会话信息:chrome=79.0.3945.117)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“gh_code2.py”,第69行,在
驱动程序。通过xpath(“//a[@class=“nav next taLnk ui_button primary”]”查找元素。单击()
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,第394行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,第978行,在find\u元素中
'value':value})['value']
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“.\Programs\Python\Python37\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“xpath”,“选择器”:”//a[@class=“nav next taLnk ui_button primary”]”
(会话信息:chrome=79.0.3945.117)

不幸的是,根据我清理站点的经验,如果站点被更新,并且那些xpath引用消失,那么必须更新脚本。在这种情况下,似乎

class="nav next taLnk ui_button primary"
不再是一个可行的选择。如果这是一个公共引用,并且随着时间的推移具有类似的结构,我会尝试使用迭代,而不是确切的类名。i、 e.导航按钮[0]或类似的东西(我面前没有确切的语法)

否则,请查看FireFox的selenium IDE浏览器。它可以帮助您在单击网站时找到引用项目的其他方式


希望这是一些帮助

您正在搜索的xpath为
nav next taLnk ui_button primary
的按钮似乎已不存在。您必须更新代码以匹配新页面。@IgnacioAguirre这听起来像是一个错误。编辑您的问题并询问实际问题,而不是寻求帮助解决问题。你想干什么?
class="nav next taLnk ui_button primary"