硒 Python.在下一页上重复解析操作不起作用



所以我要完成的工作是使用美丽的汤来解析和从页面上拉下信息,然后使用硒导航到下一页,重复此操作,直到有没有下一页。这是我对

有问题的相关代码段
while True:
    try:
        for content in cards.find_all('div',{'class':'el-card-visual'}): 
            print (content.find('img')['alt'])
            print (content.find('a')['href']) 
        elm = driver.find_element_by_css_selector('span.is-next')
        elm.click()
        URL = driver.current_url 
        driver.get(URL)
        HTML = driver.page_source
        cards = BeautifulSoup(HTML,'lxml') 
    except:
        break

当我尝试运行此问题时,我会收到此错误:

Traceback (most recent call last):
File "testpull.py", line 18, in <module>
elm.click()
File "C:Program FilesPython35libsite-packagesseleniumwebdriverremotewebelement.py", line 72, in click
self._execute(Command.CLICK_ELEMENT)
File "C:Program FilesPython35libsite-packagesseleniumwebdriverremotewebelement.py", line 461, in _execute
return self._parent.execute(command, params)
File "C:Program FilesPython35libsite-packagesseleniumwebdriverremotewebdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:Program FilesPython35libsite-packagesseleniumwebdriverremoteerrorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error:  Element is not clickable at point (172, 612). Other element would receive the click: <p class="cc_message">...</p>
(Session info: chrome=54.0.2840.99)
(Driver info: chromedriver=2.24.417431  (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 10.0.10240 x86_64)

我尝试运行它,而无需在Try Statment(Elm.Click()之后的所有内容)中运行它,但它不断地循环并反复打印出第一页的内容。

关于这个问题的最佳解决方案的任何想法?

我昨晚用自己的代码搞砸了一些,发现最后我的多余了一点。我所需要的只是:

elm = driver.find_element_by_css_selector('span.is-next')
elm.click()
HTML = driver.page_source
cards = BeautifulSoup(HTML,'lxml') 

别无其他。

相关内容

  • 没有找到相关文章

最新更新