How to get text from <em> by python webdriver?

别说谁变了你拦得住时间么 提交于 2019-12-13 04:30:46

问题


Is there any method for me to get the text "ABCD" as below HTML? I just know get the emement , but have no idea about to get its text.

element1= find_element_by_xpath("//caption/em")

Then how can I get "ABCD", is there any method like gettext()?

<table class='1'>
    <caption>
        <em> ABCD </em>
    </caption>
 </table>

回答1:


Access the text using text attribute:

>>> element1.text
u'ABCD'



回答2:


element1= find_element_by_xpath("//caption/em")
element1.get_attribute('innerHTML') 

And I found Beautiful Soup will be more better to get text.



来源:https://stackoverflow.com/questions/17613439/how-to-get-text-from-em-by-python-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!