web_scraper icon indicating copy to clipboard operation
web_scraper copied to clipboard

Problem in the nth-child of even indexes

Open wpsouto opened this issue 3 years ago • 3 comments

All even indexes are not found in the method below

  Future<void> loadPage() async {
     webScraper = WebScraper();
    if (await webScraper.loadFullURL('https://www.agricultura.go.gov.br/noticias.html')) {
      try {                                        
        var elements1_ok = webScraper.getElementTitle('div.g-grid.item:nth-child(1) > div > a > h2.heading');
        elements1_ok.forEach((img) => print(img));

        var elements2_notFound = webScraper.getElementTitle('div.g-grid.item:nth-child(2) > div > a > h2.heading');
        elements2_notFound.forEach((img) => print(img));

        var elements3_ok = webScraper.getElementTitle('div.g-grid.item:nth-child(3) > div > a > h2.heading');
        elements3_ok.forEach((img) => print(img));

        var elements4_notFound = webScraper.getElementTitle('div.g-grid.item:nth-child(4) > div > a > h2.heading');
        elements4_notFound.forEach((img) => print(img));

      } catch (e) {
        print(e);
      }
    }
  }

Details: nth-child (2) returns the empty value nth-child (3) returns the value nth-child (2) The same is happening for all elements of the list

wpsouto avatar Apr 22 '21 00:04 wpsouto

I have the same problem

Laestry avatar Jul 30 '21 14:07 Laestry

it seems to be a problem with dom.dart we forked and used universal html and it worked!

Laestry avatar Jul 30 '21 15:07 Laestry

Hi @Laestry! Would you like to contribute for the same?

tusharojha avatar Jul 30 '21 15:07 tusharojha