简体   繁体   English

如何使用Selenium Python收集行

[英]How to Collect the line with Selenium Python

I want to know how I can collect line, mailto link using selenium python the emails contains @ sign in the contact page I tried the following code but it is somewhere works and somewhere not.. 我想知道我如何使用硒python收集行,mailto链接,电子邮件中的@包含联系人列表中的@符号,我尝试了以下代码,但它在某处有效而在某处无效。

//*[contains(text(),"@")]

the emails formats are different somewhere it is <p>Email: name@domain.com</p> or <span>Email: name@domain.com</span> or <a href="mailto:name@domain.com">name@domain.com</a> 电子邮件格式在<p>Email: name@domain.com</p><span>Email: name@domain.com</span><a href="mailto:name@domain.com">name@domain.com</a>

is there anyway to collect them with one statement.. 无论如何,只用一个陈述就可以收集它们。

Thanks 谢谢

这是您在寻找我的朋友的XPath。

//*[contains(text(),"@")]|//*[contains(@href,"@")]

You could create a collection of the link text values that contain @ on the page and then iterate through to format. 您可以在页面上创建一个包含@的链接文本值的集合,然后迭代进行格式化。 You are going to have to format the span like that has Email: name@domain.com anyway. 无论如何,您都将必须格式化具有电子邮件地址:name@domain.com的跨度。

Use find_elements_by_partial_link_text to make the collection. 使用find_elements_by_partial_link_text进行收集。

I think you need 2 XPath. 我认为您需要2个XPath。 First XPath for finding element that contains text "Email:", second XPath for element that contains attribute "mailto:". 用于查找包含文本“ Email:”的元素的第一个XPath,用于包含属性“ mailto:”的元素的第二个XPath。

//*[contains(text(),"Email:")]|//*[contains(@href,"mailto:")]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM