Html Agility Pack c# Paragraph parsing problem

后端 未结 2 924
广开言路
广开言路 2021-01-23 23:10

I am having a couple of issues with my code, I am trying to pull every paragraph from a page, but at the moment it is only selecting the last paragraph.

here is my code.

2条回答
  •  温柔的废话
    2021-01-23 23:22

    IMO, XPath is no fun. I'd recommend using LINQ syntax instead:

    foreach (var node in doc.DocumentNode
        .DescendantNodes()
        .Single(x => x.Id == "body")
        .DescendantNodes()
        .Where(x => x.Name == "p")) 
    {
        string text = node.InnerText;
        lblTest2.Text = text;
    }
    

提交回复
热议问题