Sto lavorando su un web raschietto. Il seguente testo mostra i risultati del codice fornito alla fine di questa domanda, che ottiene i valori di tutti gli hrefs da una pagina.
Voglio solo ottenere valori che contengano docid=
index.php? pageid = a45475a11ec72b843d74959b60fd7bd64556e8988583f
#
summary_of_documents.php
index.php? pageid = a45475a11ec72b843d74959b60fd7bd64579b861c1d7b
#
index.php? pageid = a45475a11ec72b843d74959b60fd7bd64579e0509c7f0 & apform = magistratura
decisions.php? doctype = Decisioni / Risoluzioni firmate & docid = 1263778435388003271 # sam
decisions.php? doctype = Decisioni / Risoluzioni firmate & docid = 12637789021669321156 # sam
? doctype = Decisions / Signed Resolutions & year = 1986 & month = January # head
? doctype = Decisioni / Risoluzioni firmate e anno = 1986 & mese = febbraio # testa
Ecco il codice:
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");
}
Come posso fare questo?
Perché non sostituirlo semplicemente:
links.Add(nd.Attributes["href"].Value);
con questo:
if (nd.Attributes["href"].Value.Contains("docid="))
links.Add(nd.Attributes["href"].Value);