in reply to Re: Mojo Dom extract
in thread Mojo Dom extract

Because I don't know how to do it efficiently if possible, ie without 10 lines like :

$dom->find('div.date')->map(sub{$_->children->each})->map(sub{$_->text})->each

$dom->find('div.lieu')->map(sub{$_->children->each})->map(sub{$_->text})->each .. etc

Would like:

Dom->ret->a => anchor

Dom->ret->rtm->date => date fields .. etc

Replies are listed 'Best First'.
Re^3: Mojo Dom extract
by Anonymous Monk on May 27, 2015 at 09:56 UTC

    Because I don't know how to do it efficiently if possible, ie without 10 lines like :

    First do it any way possible, later reduce it :)

    Anyway ,

    for my $ret ( $dom->find('div.ret')->each ){ for my $aaaa ( $ret->find('a')->each ){ my $date = $aaaa->find('div.date')->first->all_text; my $lieu = $aaaa->find('div.lieu')->first->all_text; my $cat = $aaaa->find('div.cat')->first->all_text; my $titl = $aaaa->find('h2.title')->first->all_text; print join( "\t#\t", $date, $lieu, $cat, $titl), "\n"; } } __END__ 22 mai 19:52 # Dourdan # Blue # Text 1 Title 22 mai 11:55 # Champigny-sur-Marne # Blue # Text 2 t +itle

      Thank you very much, work is done ^^

      According to my understanding (perhaps wrong), find is not optimal (with a lot of html files) instead of selecting fields from parent with child nodes but I dont know how to manipulate children / child_notes and so on..

      Something like that :

      for each loop = child of ret do url1 = loop.child[1].href date = loop.child[2].child[1].child[1].text + loop.child[2].child[ +1].child[2].text + loop.child[2].child[1].child[3].text .. end loop
        right or wrong, is it important? I think not