Anglesharp get p , h and img tags

555 views Asked by At

I want to take h p and img element from HTML page but I didn't find how can I do this on anglesharp.I can take all p tags but I want to take all p h and img element respectively.

I can take like this :

        var config = Configuration.Default.WithDefaultLoader();
        var context = BrowsingContext.New(config);
        var document = await context.OpenAsync("any_site");            
        var elements = document.Body.QuerySelectorAll("p");

I try this but does not work

        var elements = document.Body.QuerySelectorAll("p h1 h2 h3 h4 h5 img");

How can I do this ?

1

There are 1 answers

0
Florian Rappl On

Use a comma to separate different selections:

var elements = document.Body.QuerySelectorAll("p, h1, h2, h3, h4, h5, img");

Just having a space is the descendants selector, which looks in the pool of children and their children recursively.