作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试获取文本 $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/
我是一名优秀的程序员,十分优秀!