仅提取某些html文本

时间:2019-03-18 22:53:03

标签: c# html regex strip

在C#中使用正则表达式,我能够将此HTML文本转换为纯文本,但是我试图仅获取文本的电子邮件部分。只能获取此HTML的电子邮件正文,而不能获取问候语或退出部分吗?

@Entity
@Table(name="Ingredients")
public class Ingredient implements Serializable {       
    @Id
    @ManyToOne
    @JoinColumn(name="FoodId")
    private Food food;

    @Id
    @ManyToOne
    @JoinColumn(name="IngredientId")
    private Food ingredient;

    @Column(name="Amount")
    private int amount;
    .
    .
    .

1 个答案:

答案 0 :(得分:0)

我建议HTML Agility pack用于使用HTML。您可能可以使用HTML Agility Pack做到这一点:

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("<p style=\"font - size: 11pt; font - family: Times; \">December 28, 2018</p><p style = \"font-size: 11pt;font-family: Times;\" > Dear Lisa,</ p >" +
                     "<p style=\"font-size: 11pt;font-family: Times;\"> I would love to grab coffee with you!<br clear = \"none\"> When does that work ? </ p >< p style = \"font-size: 11pt;font-family: Times;\" > Best Regards,</ p >");

foreach (var nodeData in doc.DocumentNode.SelectNodes("//text()"))
{
    Console.WriteLine(nodeData.InnerText);
}

打印:

December 28, 2018

 Dear Lisa,

 I would love to grab coffee with you!

 When does that work ?

 Best Regards,