【发布时间】:2018-06-06 02:16:21
【问题描述】:
我正在尝试抓取购物车商品并获取购物网站的相应价格。
到目前为止,这是我的代码,但出现错误。我想我没有得到正确的 XPath
from selenium import webdriver
chrome_path =r"C:\Users\aq4'july\Desktop\chromedriver.exe"
driver = webdriver.Chrome()
driver.get("https://www.myntra.com/")
#User Login
driver.find_element_by_xpath("""//*[@id="desktop-header-cnt"]/div[2]/div[2]/div/div[2]/div[2]/div[2]/a[2]""")
我得到的错误是
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
driver.find_element_by_xpath("""//*[@id="desktop-header-cnt"]/div[2]/div[2]/div/div[2]/div[2]/div[2]/a[2]""").click()
File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webelement.py", line 501, in _execute
return self._parent.execute(command, params)
File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "C:\Users\aq4'july\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)
请随时分别使用用户名和密码(sarwarhayatt@outlook.com、sunset@paris)进行测试。
注意:我使用的是 python 3.6,请强调我在提问时遗漏了任何内容。
【问题讨论】:
-
表达式看起来不错,应该匹配元素。你遇到了什么错误?你试过用Explicit Wait 等待吗?
-
No.. 你能否尝试进一步扩展此代码我不知道如何列出购物车项目
-
总是把完整的错误信息(Traceback)放在有问题的地方(作为文本,而不是屏幕截图)。还有其他有用的信息。
-
我在
https://www.myntra.com页面上看不到购物车商品,而只在https://www.myntra.com/checkout/cart上看到。也许创建我们可以运行的最小工作示例。 -
@furas Done.Added 几个项目到购物车。
标签: python selenium selenium-webdriver beautifulsoup