使用python selenium从flipkart中抓取数据

时间:2017-04-04 11:59:14

标签: python selenium selenium-webdriver selenium-chromedriver

下面的代码提供了一些值,它没有显示页面中的所有值。

from selenium import webdriver
chrome_path = r"C:\Users\Venkatesh\AppData\Local\Programs\Python\Python35\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.flipkart.com/mobiles")
search = driver.find_element_by_xpath("""//*[@id="container"]/div/div[2]/div/div[3]/div[1]/div/div[4]/div[1]/div/div/a""").click()
timeout = 20
posts = driver.find_elements_by_class_name("iUmrbN")
for post in posts:
    print(post.text)

我得到的输出如下,错误也显示如何解决这些问题

  Sony Xperia XZs
    Moto g5 Plus
    Swipe Elite Sense
    OPPO F3 Plus (Gold, 64 GB)








    SAMSUNG On Nxt
    Swipe Elite Max (Onyx Black, 32 GB)
    Lenovo K5 Note (4GB)
    Zenfone 3 Laser




    Traceback (most recent call last):
      File ".\ff1.py", line 9, in <module>
        print(post.text)
      File "C:\Users\Venkatesh\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\remote\webelement
    .py", line 73, in text
        return self._execute(Command.GET_ELEMENT_TEXT)['value']
      File "C:\Users\Venkatesh\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\remote\webelement
    .py", line 491, in _execute
        return self._parent.execute(command, params)
      File "C:\Users\Venkatesh\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\remote\webdriver.
    py", line 238, in execute
        self.error_handler.check_response(response)
      File "C:\Users\Venkatesh\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\remote\errorhandl
    er.py", line 193, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to
    the page document
      (Session info: chrome=57.0.2987.133)
      (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT
     

6.2.9200 x86_64)

0 个答案:

没有答案