Selenium Python如何从<div>获取文本(html源代码)

Jul*_*lia 6 python tags selenium

我正在尝试$27.5在tag中获取文本<div>,我通过id找到元素,元素称为"price".

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>
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的

price.text
price.get_attribute('value')
Run Code Online (Sandbox Code Playgroud)

以上两种都不起作用.

更新: 感谢所有试图提供帮助的人.我把你的答案结合在一起,得到了解决方案:)

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

Mal*_*imi 2

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

re.search(r'<div.*?>(*.?)</div>', price.get_attribute('innerHTML')).group(1)
Run Code Online (Sandbox Code Playgroud)