Sto usando HtmlAgilityPack
e sto cercando di ottenere una specifica a
tag che contiene un particolare testo all'interno. Supponiamo che io abbia questa struttura html:
<ul>
<li class="current">
<a href="/matches/2018/05/20/italy/serie-a/ss-lazio-roma/fc-internazionale-milano/2539153/">Summary</a>
</li>
<li class="">
<a href="/matches/2018/05/20/italy/serie-a/ss-lazio-roma/fc-internazionale-milano/2539153/head2head/">H2H Comparison</a>
</li>
<li class="">
<a href="/matches/2018/05/20/italy/serie-a/ss-lazio-roma/fc-internazionale-milano/2539153/commentary/">Commentary</a>
</li>
<li class=""><a href="/matches/2018/05/20/italy/serie-a/ss-lazio-roma/fc-internazionale-milano/2539153/venue/">Venue</a>
</li>
<li class="">
<a href="/matches/2018/05/20/italy/serie-a/ss-lazio-roma/fc-internazionale-milano/2539153/map/">Map</a>
</li>
</ul>
Voglio ottenere il a
tag che contiene come InnerText
: "Sede". In realtà la mia idea è questa:
var nodes = nodes.SelectNodes("//li//a");
HtmlNode a;
foreach(var node in nodes)
{
if(node.InnerText.ToLower().Contains("venue"))
{
a = node;
break;
}
}
questo è il codice funzionante ma esiste un altro modo, magari usando xpath o qualcosa del genere?
Ciò restituirà tutti i tag di ancoraggio che contengono la parola "Venue" //a[contains(text(),'Venue')]