我正在嘗試在谷歌地圖網頁上收集資料,這是鏈接。
解決方案是什么?
編輯:這就是我想要得到的。
uj5u.com熱心網友回復:
至少在我這邊,我認為不需要滾動。
以下代碼有效:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 20)
url = "https://www.google.com/maps/place/Amsterdamsche Athleten Club Hercules/@52.36937,4.8049968,16z/data=!4m5!3m4!1s0x47c5e3c9cbb3d913:0xef85f93ef996cc06!8m2!3d52.3692292!4d4.8056684"
driver.get(url)
name = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-item-id='authority']"))).text
print(name)
輸出:
aachercules.nl
使用 XPath 而不是 CSS 選擇器也可以做到這一點。
這是我使用的 XPath:
name = wait.until(EC.visibility_of_element_located((By.XPATH, "//a[@data-item-id='authority']"))).text
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/531101.html
標籤:python-3.x硒硒网络驱动程序路径css 选择器
上一篇:如何在我的代碼DateTimeStartTime=StartDateValue StartTimeNames[0]中實作這一點?
下一篇:Selenium無法獲取此類