【发布时间】:2021-12-03 22:02:47
【问题描述】:
我是 python selenium 包的新手。我正在为 bookie 网站开发爬虫。
我无法点击并打开图片链接。
我的代码:
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
web = 'https://odibets.com/'
driver.get(web)
driver.implicitly_wait(3)
# btn = driver.find_element_by_css_selector('span.icon')""
btn = driver.find_element_by_xpath("//a[@href='/League'] and //span[text()='League']")
# <img src="https://s3-eu-west-1.amazonaws.com/odibets/img/menu/odi-league-2.png">
# //img[@src ="https://s3-eu-west-1.amazonaws.com/odibets/img/menu/odi-league-2.png"]
# //span[text()='League']
btn.click()
我得到以下异常。
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //a[@href='/League'] and //span[text()='League'] because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type. (Session info: chrome=96.0.4664.45) Stacktrace: Backtrace: Ordinal0 [0x010D6903+2517251]
【问题讨论】:
标签: python-3.x selenium