Ho il seguente codice HTML:
<tbody>
<tr>
<td class="metadata_name">Headquarters</td>
<td class="metadata_content">Princeton New Jersey, United States</td>
</tr>
<tr>
<td class="metadata_name">Industry</td>
<td class="metadata_content"><ul><li><a href="/q-Engineering-Software-jobs.html" rel="nofollow">Engineering Software</a></li><li><a href="/q-Software-Development-&-Design-jobs.html" rel="nofollow">Software Development & Design</a></li><li><a href="/q-Software-jobs.html" rel="nofollow">Software</a></li><li><a href="/q-Custom-Software-&-Technical-Consulting-jobs.html" rel="nofollow">Custom Software & Technical Consulting</a></li></ul></td>
</tr>
<tr>
<td class="metadata_name">Revenue</td>
<td class="metadata_content">$17.5 Million</td>
</tr>
<tr>
<td class="metadata_name">Employees</td>
<td class="metadata_content">201 to 500</td>
</tr>
<tr>
<td class="metadata_name">Links</td>
<td class="metadata_content"><ul><li><a href="/url?q=http%3A%2F%2Fwww.site.com&h=085df2ca" target="_blank">Company website</a></li></ul></td>
</tr>
</tbody>
Voglio essere in grado di caricare il valore di metadata_content (ex "$ 17,5 milioni") in una var dove il metadata_name è = a un valore (es: "Revenue").
Ho provato a utilizzare combinazioni di codice come questa per alcune ore ...
orgHtml.DocumentNode.SelectNodes("//td[@class='metadata_name']")[0].InnerHtml;
Ma non sto ottenendo la giusta combinazione. Se si dispone di una sintassi utile di SelectNodes - che mi procurerà la soluzione, lo apprezzerei.
Sembra che quello che stai cercando sia questo:
var found = orgHtml.DocumentNode.SelectSingleNode(
"//tr[td[@class = 'metadata_name'] = 'Revenue']/td[@class = 'metadata_content']");
if (found != null)
{
string html = found.InnerHtml;
// use html
}
Nota che per ottenere il testo di un elemento devi usare found.InnerText
, non found.InnerHtml
, a meno che tu non abbia specificamente bisogno del suo contenuto HTML.