pycharm python硒刮板显然未打印正确的值

问题描述 投票:0回答:1

我是python,selenium,pycharm等的新手。

我正在尝试在网站上打印a的值(在编写此值时,该值是6320。代码没有给出错误,但没有打印出任何内容。

正如您在屏幕快照中所看到的,当我调试并将鼠标悬停在变量上时,它显示6320,这是我要查找的值。

我在做什么错?

非常感谢您的帮助!

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located

#This example requires Selenium WebDriver 3.13 or newer
with webdriver.Chrome() as driver:
    wait = WebDriverWait(driver, 10)
    driver.get("https://ici.radio-canada.ca/info/2020/coronavirus-covid-19-pandemie-cas-carte-maladie-symptomes-propagation/")

    driver.implicitly_wait(5)

    items = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[3]/div[3]/div[1]/table/tbody/tr[2]/td[1]/span[2]').text


    print(items)
    print("hello")

pycharm span value not printing

python selenium selenium-webdriver pycharm selenium-chromedriver
1个回答
0
投票

您需要等到.visibility_of_element_located并使用此xpath//td[contains(., "Total*")]//span[last()],尽管您的xpath也可以使用,但它是绝对的xpath,很容易更改。

with webdriver.Chrome() as driver:
    wait = WebDriverWait(driver, 10)
    driver.get("https://ici.radio-canada.ca/info/2020/coronavirus-covid-19-pandemie-cas-carte-maladie-symptomes-propagation/")
    items = wait.until(EC.visibility_of_element_located((By.XPATH, '//td[contains(., "Total*")]//span[last()]'))).text
    print(items)
    print("hello")
© www.soinside.com 2019 - 2024. All rights reserved.