我试图检查这个网站上的其他答案,但他们都没有为我工作。我有以下HTML代码:如何从XPATH获取URL?
<h3 class="x-large lheight20 margintop5">
<a href="http://someUrl.com" class="marginright5 link linkWithHash detailsLink"><strong>some textstring</strong></a>
</h3>
我想从这个文件得到#与下面的代码:
string adUrl = Doc.DocumentNode.SelectSingleNode("//*[@id=\"offers_table\"]/tbody/tr["+i+ "]/td/table/tbody/tr[1]/td[2]/div/h3/a/@href").InnerText;
我也想这样做没有@href
。还试用a[contains(@href, 'searchString')]
。但所有这些行给我的链接的名称 - 一些文本字符串
InnerText?你为什么试图使用它,而不是获取属性(这是什么'href'是?像http://stackoverflow.com/questions/3750678/getting-attribute-value-of-an-xml-document-using-c -sharp –