【问题标题】:Printing Text from Element Selenium Python从 Element Selenium Python 打印文本
【发布时间】:2021-07-24 16:07:43
【问题描述】:

我想将此部分打印到控制台。 (标记)Image

这是我最后一次尝试:

我在上次尝试时收到此错误:

无法定位元素:

{"method":"xpath","selector":"//*[@id="react-root"]/section/main/div/ul/li[2]/a/span"}

请保留我的此文本更改。

followers = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/ul/li[2]/a/span').GetAttribute("innerHTML")

print("Followers: " + followers)

【问题讨论】:

标签: python selenium selenium-webdriver instagram


【解决方案1】:

您可以使用以下 xpath :

//a[contains(@href, 'followers')]/span

Selenium - Python 绑定中没有任何GetAttribute 方法可用。

相反,您可以使用:

followers = driver.find_element_by_xpath("//a[contains(@href, 'followers')]/span").get_attribute("innerHTML")
print("Followers: ", followers)

【讨论】:

    【解决方案2】:

    你能检查一下吗

    followerTxt=driver.find_element_by_xpath("((//a[@class='-nal3 ']/span)[2])")
    
    print("Total followers: ",followerTxt.text)
    

    我根据元素索引检查过

    这是我的输出

    【讨论】:

    • 嘿,这行得通,但是错了。我有多少我关注,而不是我有多少关注者。
    • @Zetlex DK 你能检查我更新的答案吗,我包括输出的快照,显示关注者而不是你关注的数量
    猜你喜欢
    • 2022-01-09
    • 2020-01-16
    • 1970-01-01
    • 2012-01-09
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2022-01-21
    相关资源
    最近更新 更多