Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi, for many hours I'm trying to extract needed text from a html format (by LWP::UserAgent). I need those text which are not in html tags: '< >' brackets. I wrote many codes, it seems my regexp not so good :-), I'll be happy if we can solve it togather, tnx...

example of html text: <h1>Volume Leaders</h1></div><div class="yfitabs"><div id="yfitt" class="yfitt"><ul><li class="on"><a href="/actives?e=us"><em>US</em></a></li><li><a href="/actives?e=o"><em>NASDAQ</em></a></li><li><a href="/actives?e=aq"><em>AMEX</em></a></li><li><a href="/actives?e=nq"><em class="last">NYSE</em></a></li></ul></div><div id="yfitp" class="yfitabsc"><table cellpadding="0" cellspacing="0"><thead><th class="first">Symbol</th><th class="second">Name</th><th>Last Trade</th><th>Change</th><th>Volume</th><th class="last">Related Info</th></thead><tbody><tr><td class="first"><b><a href="/q?s=BAC">BAC</a></b></td><td class="second name">Bank of America Corporation Com</td><td class="last_trade"><b><span id="yfs_l10_bac">8.06</span></b> <nobr><span id="yfs_t10_bac">Jul 3</span></nobr></td><td><span id="yfs_c10_bac"><img width="10" height="14" style="margin-right:-2px;" border="0" src="http://l.yimg.com/a/i/us/fi/03rd/up_g.gif" alt="Up"> <b style="color:#008800;">0.01</b></span> <span id="yfs_p20_bac"><b style="color:#008800;"> (0.12%)</b></span></td><td><span id="yfs_v00_bac">57,655,357</span></td><td class="last"><a href="/q/bc?s=BAC">Chart</a>, <a href="/q/pr?s=BAC">Profile</a>, <a href="/q?s=BAC">More</a></td></tr><tr><td class="first"><b><a href="/q?s=SIRI">SIRI</a></b></td><td class="second name">Sirius XM Radio Inc.</td><td class="last_trade"><b><span id="yfs_l10_siri">2.04</span></b> <nobr><span id="yfs_t10_siri">Jul 3</span></nobr></td><td><span id="yfs_c10_siri"><img width="10" height="14" style="margin-right:-2px;" border="0" src="http://l.yimg.com/a/i/us/fi/03rd/up_g.gif" alt="Up"> <b style="color:#008800;">0.06</b></span> <span id="yfs_p20_siri"><b style="color:#008800;"> (2.77%)</b></span></td><td><span id="yfs_v00_siri">53,607,894</span></td><td class="last"><a href="/q/bc?s=SIRI">Chart</a>, <a href="/q/pr?s=SIRI">Profile</a>, <a href="/q?s=SIRI">More</a></td></tr><tr><td class="first"><b><a href="/q?s=F">F</a></b></td><td class="second name">Ford Motor Company Common Stock</td><td class="last_trade"><b> EXAMPLE OF CODE:
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request::Common qw(GET); my $ua = LWP::UserAgent->new; # Define user agent type $ua->agent('MyApp/0.1 '); # Request object my $req = GET 'http://finance.yahoo.com/actives?e=us'; # Make the request my $res = $ua->request($req); #my @con = $res->content; $res->content =~ /(<div class="yfitbg tbtabs">)(<h1>Volume Leaders.*)( +Get a)/s; my $cont = $2; print $cont, "\n"; exit 0;

In reply to regexp solutions by programmer.perl

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



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found