【发布时间】:2014-11-12 11:21:16
【问题描述】:
我在 ASP.NET 中使用 HtmlAgilityPack 抓取 HTML DOM 元素。目前我的代码正在加载所有 href 链接,这意味着子链接的子链接也。但我只需要我的域 URL 的依赖 URL。我不知道如何为它编写代码。任何人都可以帮我做到这一点吗? 这是我的代码:
public void GetURL(string strGetURL)
{
var getHtmlSource = new HtmlWeb();
var document = new HtmlDocument();
try
{
document = getHtmlSource.Load(strGetURL);
var aTags = document.DocumentNode.SelectNodes("//a");
if (aTags != null)
{
outputurl.Text = string.Empty;
int _count = 0;
foreach (var aTag in aTags)
{
string strURLTmp;
strURLTmp = aTag.Attributes["href"].Value;
if (_count != 0)
{
if (!CheckDuplicate(strURLTmp))
{
lstResults.Add(strURLTmp);
outputurl.Text += strURLTmp + "\n";
counter++;
GetURL(strURLTmp);
}
}
_count++;
}
}
}
【问题讨论】:
-
"..depending URL of my domain URL"是什么意思?
标签: c# asp.net html-agility-pack