scraping data from flipkart using python selenium

独自空忆成欢 提交于 2019-12-24 09:09:16

问题


Below code gives few of values it's not displaying all values in the page.

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)

I am getting output like below and error also showing how to solve these problem

  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)

来源:https://stackoverflow.com/questions/43206630/scraping-data-from-flipkart-using-python-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!