我正在尝试从此站点提取标准公交车,但由于没有唯一标识符,因此无法引用该元素。此外,元素的位置可能会根据表格的扩展或收缩而改变。
是否可以从标准公交系统中抓取日期
1)基于标题(标准公交车) 2)无需转到“运送事实”标签
我正在使用Python 3.7和Chrome
示例:https://www.fedex.com/apps/fedextrack/?tracknumbers=478239726746
预先感谢您的帮助。
答案 0 :(得分:0)
尝试一下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="chromedriver.exe")
wait = WebDriverWait(driver, 30)
driver.get("https://www.fedex.com/apps/fedextrack/?tracknumbers=478239726746")
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"div.detailViewTabs_area >ul >li.factsTab > a"))).click()
wait.until(EC.visibility_of(driver.find_element(By.CSS_SELECTOR,"div.dp_facts_area")))
standardTransitDate = wait.until(EC.visibility_of(driver.find_element(By.XPATH,"//em[contains(.,'Standard transit ')]/following-sibling::span")))
print(standardTransitDate.text)
driver.quit()
答案 1 :(得分:0)