HTML 敏捷包 - 筛选 Href 值结果
本文关键字:Href 结果 筛选 HTML | 更新日期: 2023-09-27 18:30:38
我正在研究一个网络爬虫。以下文本显示了此问题末尾给出的代码的结果,该代码从页面中获取所有 href 的值。
我只想获取包含docid=
的值
index.php?pageid=a45475a11ec72b843d74959b60fd7bd64556e8988583f
#
summary_of_documents.php
index.php?pageID=A45475A11ec72b843d74959b60fd7bd64579b861c1d7b
#
index.php?pageid=a45475a11ec72b843d74959b60fd7bd64579e0509c7f0&apform=judiciary
决策.php?文档类型=决策/已签名 分辨率&docid=1263778435388003271#sam
决策.php?文档类型=决策/已签名 分辨率&docid=12637789021669321156#sam
?doctype=決策/簽署決議&年份=1986&月=一月#head
?doctype=决定/签署的决议&年=1986&月=二月#头
代码如下:
string url = urlTextBox.Text;
string sourceCode = Extractor.getSourceCode(url);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(sourceCode);
List<string> links = new List<string>();
if (links != null)
{
foreach (HtmlAgilityPack.HtmlNode nd in doc.DocumentNode.SelectNodes("//a[@href]"))
{
links.Add(nd.Attributes["href"].Value);
}
}
else
{
MessageBox.Show("No Links Found");
}
if (links != null)
{
foreach (string str in links)
{
richTextBox9.Text += str + "'n";
}
}
else
{
MessageBox.Show("No Link Values Found");
}
我该怎么做?
为什么不直接替换它:
links.Add(nd.Attributes["href"].Value);
有了这个:
if (nd.Attributes["href"].Value.Contains("docid="))
links.Add(nd.Attributes["href"].Value);