问题描述
我想写一个xpath表达式给 ONLY 打印所有class - insights type1的文本。
以下CSS选择器为我提供了Insights弹出窗口的所有标签
driver.find_elements_by_css_selector(#body> div.side-module.expanded> div.content)
有人可以帮忙吗?
谢谢
// div
解决方案[@ class =content] / div [@ class =insights type1]
请致电并获取每个div的文本: driver.find_elements_by_xpath('// div [@ class =content] / div [@ class =insights type1]'):
print div.text
请注意,如果您需要d只有一个div,只需使用:
div =驱动程序。 find_element_by_xpath('// div [@ class =content] / div [@ class =insights type1]')
print div.text
另外,如果 div
s可以超出 content
div
太 - 使用 // div [@ class =insights type1]
。
希望有所帮助。
Hi,
I would like to write an xpath expression to ONLY print the text for all the "class - insights type1". I don't need to print the ones that has "hide" .
Following CSS selector gives me all the tags for the Insights popup
driver.find_elements_by_css_selector("#body > div.side-module.expanded > div.content")
Can someone help with this please?
Thanks
Here's how you can do this:
//div[@class="content"]/div[@class="insights type1"]
In python call find_elements_by_xpath()
and get the text of each div found:
for div in driver.find_elements_by_xpath('//div[@class="content"]/div[@class="insights type1"]'):
print div.text
Note that if you need only one single div, use just find_element_by_xpath()
:
div = driver.find_element_by_xpath('//div[@class="content"]/div[@class="insights type1"]')
print div.text
Also, if these div
s can be outside of content
div
too - use //div[@class="insights type1"]
.
Hope that helps.
这篇关于如何从下面的HTML制定Xpath表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!