我需要從網頁中提取文本&並在我的控制檯中打印。 Xpath提取這些文本:使用xpath-selenium-python從網頁中提取文本/數字
嘗試這樣做時,我只能得到0,但這些xpath應返回與其關聯的數字&的文本值。
需要幫助!
import time
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
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import ElementNotVisibleException
def init_driver():
driver = webdriver.Chrome()
driver.wait = WebDriverWait(driver, 5)
return driver
def lookup(driver,uname,pwd):
driver.get("URL")
box = driver.wait.until(EC.presence_of_element_located((By.NAME, "j_username")))
box.send_keys(uname)
box = driver.wait.until(EC.presence_of_element_located((By.NAME, "j_password")))
box.send_keys(pwd)
button = driver.wait.until(EC.element_to_be_clickable((By.NAME, "login")))
button.click()
button = driver.wait.until(EC.presence_of_element_located((By.ID, "fetchCandidateChanges_0")))
button.click()
#element = driver.wait.until(EC.presence_of_element_located(By.CLASS_NAME, "desc"))
driver.wait = WebDriverWait(driver, 15)
element = driver.find_element_by_xpath("//label[@id='PUSHED']")
k=element.text
print(k)
if __name__ == "__main__":
driver = init_driver()
lookup(driver,"ddd","ppp")
time.sleep(15)
driver.quit()
能否請您分享的HTML – Monika