使用HTMLAgilityPack仅获取href的URL [英] Grabbing just the URL of an href using HTMLAgilityPack
本文介绍了使用HTMLAgilityPack仅获取href的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我要解析的HTML源代码:
Here is the HTML source I'm trying to parse:
<a style='white-space: nowrap;' href='/AuthorStories-4931/dreamfall.htm'><img class='donoricon' alt='(Current Donor)' title='(Current Donor)' src='http://static.tthf.me/images/donors/Current%20Donor.gif'/>dreamfall</a>
这是我正在使用的代码:
Here is the code I'm using:
authorLink = doc.DocumentNode.SelectSingleNode("//a[contains(@href, 'AuthorStories')]").OuterHtml;
这可以正确捕获链接,但也可以捕获img.我要抓住的唯一部分是href段.关于如何仅解析该特定部分的任何建议?
This grabs the link correctly, but it also captures the img as well. The only part I want to grab is the href segment. Any suggestions on how to parse out just that particular section?
推荐答案
[几年来没有碰过HtmlAgilityPack,但这通常是正确的]
SelectSingleNode
返回的节点上应该有一个Attributes
数组,而不是使用OuterHtml
,您应该能够从那里获取href
.
Instead of taking OuterHtml
, there should be an Attributes
array on the node returned by SelectSingleNode
, you should be able to get href
from there.
这篇关于使用HTMLAgilityPack仅获取href的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文