简体   繁体   English

如何使用Xpath引用类中的标记

[英]How to Reference Tag in a Class using Xpath

I'm trying to figure out how to get the link for the website by referencing the class pv-contact-info__contact-type ci-websites using xpath and selenium. 我试图通过使用xpath和selenium引用类pv-co​​ntact-info__contact-type ci-websites来弄清楚如何获得该网站的链接。

[Here is the html I'm trying to reference][1] [这是我要参考的html] [1]

sel = Selector(text=driver.page_source)
website = sel.xpath("//*[@class='pv-contact-info__contact-type ci websites']")
print website

When I print "website" I expect there to be a list of all the things under the HTML class referenced in the code. 当我打印“网站”时,我希望在代码中引用的HTML类下有所有列表。 Instead, I get an empty list. 相反,我得到一个空列表。

Ideally, I would want to just be able to get the website link. 理想情况下,我只希望能够获得网站链接。

EDIT: 编辑:

I'm now able to reference the specific line by doing the line below but I'm not sure how to extract the link. 现在,我可以通过执行以下行来引用特定行,但是我不确定如何提取链接。

//*[starts-with(@class,'pv-contact-info__contact-type ci-websites')]/ul/*/*/a 

You are missing - between ci websites . 您不见了-ci websites之间。

Use the below xpath. 使用下面的xpath。

//*[@class='pv-contact-info__contact-type ci-websites']

Edit 1: updated based on conversation in the comments. 编辑1:根据评论中的对话进行更新。

website = sel.xpath(" //*[starts-with(@class,'pv-contact-info__contact-type ci-websites')]/ul//a').get()

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

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