gpt4 book ai didi

python - Selenium Python 如何从
获取文本(html 源)

转载 作者:太空狗 更新时间:2023-10-30 00:19:29 24 4
gpt4 key购买 nike

我正在尝试获取文本 $27.5内部标签 <div> ,我通过 id 定位元素,该元素称为“价格”。

html片段如下:

<div id="PPP,BOSSST,NYCPAS,2015-04-26T01:00:00-04:00,2015-04-26T05:20:00-04:00,_price" class="price inlineBlock strong mediumText">$27.50</div>

这是我试过的

price.text
price.get_attribute('value')

以上两个都不行。

更新:感谢所有试图提供帮助的人。我将您的答案结合在一起并得到了解决方案:)

    price = driver.find_element_by_xpath("//div[@class='price inlineBlock strong mediumText']")
price_content = price.get_attribute('innerHTML')
print price_content.strip()

最佳答案

难道不能用正则表达式或者Beautiful Soup在HTML中查找元素的内容吗:

re.search(r'<div.*?>(*.?)</div>', price.get_attribute('innerHTML')).group(1)

关于python - Selenium Python 如何从 <div> 获取文本(html 源),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29807856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com