Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi monks who are always smarter than me. I'm using Mojo::DOM in a script to try and parse several html files. I can return most of the text that I need but I have one piece of html that I can't seem to get. Here's the html that I'm trying to pull:

<div class="abstract-content selected" id="enc-abstract"> <p>Secondary bile acids (BAs) and short chain fatty acids (SCFAs), two major types of bacterial metabolites in the colon... </p>

and here is the code that I've been trying to use. The commented out items are my many attempts at trying to get it to work and trying to look at some of my older code and other code out there.

#<div class="abstract-content selected" id="enc-abstract"> # my $abstr = $dom1->find('p[strong.class^="sub-title"]' +)->map( sub{ $_->text } )->map( sub{ s|\n| |gr } ); #div[enc-abstract] #'div["abstract-content selected" id^="enc-abstract"]' #'div[class^="officerOuter officerInner"] # $r2 = $dom2->find( '[class="1YTREF"]' ) -> map( +sub{ $_->text } ); #my $abstr = $dom1->find('div[class^="abstract-content s +elected"]')->map( sub{ $_->text } )->map( sub{ s|\n| |gr } ); # $dom->find('div.openTime') # ->map(sub{$_->children->each}) # ->map(sub{$_->text}) # ->each; # my $abstr = $dom1->at('abstract-content selected') # ->find('p') # ->map( sub{ $_->text } ); my $abstr = $dom1->find('div[class^="abstract-content se +lected"]')->map( sub{ $_->text } )->map( sub{ s|\n| |gr } ); #my $abstr = $dom1->at('#abstract-content')->find('p')->ea +ch(sub { # $_; # this is the current element # }); # my $abstr = $dom1->find('.abstract-content selected' +) # ->map(sub{$_->children->each}) # ->map( sub{ $_->text } ); # #->map( sub{ s|\n| |gr } ); # print "Abstract is: $abstr\n\n";

It's the code for the paragraph in html after the class that is messing things up I believe. I read the Mojo docs over and over and tried a few tings with child nodes but failed miserably. Any help would be greatly appreciated. it's probably very simple and I was just overthinking it, up late and tired.</>


In reply to Mojo::DOM parsing question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (8)
    As of 2020-10-27 16:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (257 votes). Check out past polls.

      Notices?