1

私はWebスクレイパーに取り組んでいます。次のテキストは、この質問の最後にあるコードの結果を示しています。このコードは、ページからすべての href の値を取得します。

を含む値のみを取得したいdocid=

index.php?pageid=a45475a11ec72b843d74959b60fd7bd64556e8988583f

#

summary_of_documents.php

index.php?pageid=a45475a11ec72b843d74959b60fd7bd64579b861c1d7b

#

index.php?pageid=a45475a11ec72b843d74959b60fd7bd64579e0509c7f0&apform=司法

decision.php?doctype=決定 / 署名された決議&docid=1263778435388003271#sam

decision.php?doctype=決定 / 署名された決議&docid=12637789021669321156#sam

?doctype=Decisions / Signed Resolutions&year=1986&month=January#head

?doctype=Decisions / Signed Resolutions&year=1986&month=February#head

コードは次のとおりです。

        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");
        }

これどうやってするの?

4

1 に答える 1

2

これを置き換えてみませんか:

links.Add(nd.Attributes["href"].Value);

これとともに:

if (nd.Attributes["href"].Value.Contains("docid="))
    links.Add(nd.Attributes["href"].Value);
于 2012-04-11T08:38:04.440 に答える