我如何使用Selenium从课堂上获取文本

<div class="class-one">
<div class="class-two">
sample text
<div class="class-three">
<a href="https://google.com" target="" class="button button--outline button--purple " id="" title="search"><i class="fal fa-fw fa-file-word"></i><span class="button__title">search</span></a>
</div>
</div>
</div>

When i do driver.find_elements_by_css_selector('div.class-two') it prints sample text and search too, how can i get only sample text using selenium in python?

评论
手插口袋
手插口袋

您只需要在最后写上“文本”即可。

driver.find_element_by_css_selector('div.class-two').text
点赞
评论