문제

I'm trying to open an HTML file, loop through the divs that match a certain criteria, and then loop through the p tags that match a certain criteria within those divs.

CQ dom = CQ.CreateFromFile("page.html");
CQ document_divs = dom["div"];
document_divs.Each((i,document_div) =>
{
    string divid = document_div.Id;
    if (divid.Contains("page"))
    {
        CQ page_ptags = document_div["p"];
        page_ptags.Each((j, page_ptag) =>
        {
            lblOutput.Text = page_ptag.Id;
        });

    }

});

It is selecting the divs fine, but I'm not sure how to select the p tags within a div. I know there is something wrong with this line:

CQ page_ptags = document_div["p"];

But what should I change?

도움이 되었습니까?

해결책

Try this:

CQ page_ptags = document_div.Cq().Find("p");

다른 팁

When you are looking throw a CQ object, each elements will be type of IDom. That's why you need or wrap it in CQ object, or use native Dom functions to work with.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top