【发布时间】:2017-05-02 14:03:56
【问题描述】:
试图解析 news.google
<a target="_blank"class="article usg-AFQjCNFr5aujpYnTzdHNYfHZw_gNN6iq-w sig2-1esugE2Sy8Bhe2CzulGmsA did--5114870031117960448 esc-thumbnail-link" href="http://www.theglobeandmail.com/news/world/trump-blasts-media-in-rally-celebrating-100-days-as-president/article34858356/" url="http://www.theglobeandmail.com/news/world/trump-blasts-media-in-rally-celebrating-100-days-as-president/article34858356/" id="MAA4AEgAUABgAWoCY2E" ssid="h" >
我想要 url 属性。我无法获取 url 属性。我得到的只是空引用。
XPath 找到这个多属性元素:
HtmlNode aNodes = doc.DocumentNode.SelectSingleNode("//a[@target='_blank' and @class='article usg-AFQjCNFr5aujpYnTzdHNYfHZw_gNN6iq-w sig2-1esugE2Sy8Bhe2CzulGmsA did--5114870031117960448 esc-thumbnail-link' and @href='http://www.theglobeandmail.com/news/world/trump-blasts-media-in-rally-celebrating-100-days-as-president/article34858356/' and @url='http://www.theglobeandmail.com/news/world/trump-blasts-media-in-rally-celebrating-100-days-as-president/article34858356/' and @id='MAA4AEgAUABgAWoCY2E' and @ssid='h']");
我只是在试图找到这个元素时得到一个空引用。 url 和 href 等属性值总是在变化。有没有办法根据元素中的属性而不是属性值来获取 url?如果一个元素具有这五个属性然后选择 url 的值?非常感谢。
【问题讨论】:
标签: c# html xpath html-agility-pack