简体   繁体   English

C#HtmlNodeCollection-在元素中查找元素

[英]C# HtmlNodeCollection - Find Element inside Element

I have this code: 我有以下代码:

<div class="field">
    <label class="label">Email:</label>
    <div class="data">
        <a href="mailto:1111@gmail.com">1111@gmail.com</a>
    </div>
</div>
<a href="mailto:2222@gmail.com">2222@gmail.com</a>

So I have two email in the html page. 所以我在html页面中有两个电子邮件。 I want to get only the "1111@gmail.com" , I don't care about the "2222@gmail.com". 我只想获取“ 1111@gmail.com”,我不在乎“ 2222@gmail.com”。 I want to find specific email so I thought to find the tag and inside it I'll find the specific tag. 我想找到特定的电子邮件,所以我想找到该标签,然后在其中找到特定的标签。 Thanks in advance. 提前致谢。

Try to use HtmlAgilityPack and Xpath . 尝试使用HtmlAgilityPackXpath

    var webGet=new HtmlWeb(); 
    var docMain=webget.Load("yourUrl");
    var yourEmail=docMain.DocumentNode.SelectSingleNode("//div[@class=data]/a").Attributes["href"].Value

It should work 它应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM