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.</>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|