从<a> using XPath (@href doesn&#39;t work)

时间:2018-12-12 12:51:26

标签: parsing xpath

This should be simple but isn't.

I am using:

//*[@class="mainbody right"]//div[2]/div[2]/div[1]/div[1]/a

to generate a list of elements:

< a href="https://someurl1.com" class="title getFull" data-view="full"> Some plain text 1 < /a>

< a href="https://someurl2.com" class="title getFull" data-view="full"> Some plain text 2 < /a>

< a href="https://someurl3.com" class="title getFull" data-view="full"> Some plain text 3 < /a>

What I want instead is either:

href="https://someurl1.com"

href="https://someurl2.com"

href="https://someurl3.com"

or

https://someurl1.com

解析href      

https://someurl2.com

     

https://someurl3.com

如何摆脱不必要的类和数据视图以及纯文本?我曾尝试附加/ @ href和许多其他东西,但无济于事。

1 个答案:

答案 0 :(得分:0)

如果您真的想从position元素中获取值,则需要像这样更改XPath:

//*[@class="mainbody right"]//div[2]/div[2]/div[1]/div[1]/a/@href