【发布时间】:2021-03-05 05:07:08
【问题描述】:
我正在尝试通过此代码自动搜索简短的 google 链接:
link = 'https://www.google.com/maps/place/Sport+La+Pava/@41.273359299999996,2.0005245,14z/data=!4m8!1m2!2m1!1sSport+La+Pava!3m4!1s0x12a49d5b3d4b1753:0xeb7e41655fa9ec91!8m2!3d41.273359299999996!4d2.0005245'
from selenium import webdriver
CHROME_DRIVER_PATH = "D:\chromedriver\chromedriver.exe"
driver = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
driver.get(link)
time.sleep(3)
button1 = driver.find_element_by_id("introAgreeButton")
button1.click()
new_https = driver.find_element_by_xpath('/html/body/jsl/div[3]/div[2]/div/div[2]/div/div[3]/div/div/div[1]/div[4]/div[2]/div[1]/input').value_of_css_property()
打印(new_https)
链接是谷歌地图链接。 错误发生在 button1 = driver.find_element_by_id("introAgreeButton")。我在这里尝试通过的按钮基本上是条款和条件。我必须接受它。但每次我收到错误 NoSuchElementException
我尝试了不同的方法:使用 Xpath、完整的 Xpath、css,没有任何效果。 我对像 amazon.com 这样的网站使用相同的代码,在那里都可以正常工作,所以这与我的 webdriver 的位置或类似的东西无关。似乎非常具体的 Google 条款和条件
【问题讨论】: