fellow monks,

I have a simple script that performs a google query, strips excess html and presents the web links, that is everything contained within <a> tags. My previous approach had been to strip off everything surrounding the <a> tags, but I had the thought that simply matching the links would be a cleaner approach. I've been encountering some issues trying to formulate the regex correctly. My regex seems to be matching the entire scalar rather than extracting the result and sending it to my array. Ideally I would like to match everything within <a> tags (including the tags themselves) minus the google ad links and such. This is what I've come up with so far. Any suggestions are greatly appreciated. cheers.

#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $search = 'perlmonks'; my $ua = LWP::UserAgent->new; $ua->agent( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/200 +70309 Fire fox/2.0.0.3" ); my $req = HTTP::Request->new( GET => "http://www.google.com/search?hl=en&num=100&q=$search&btnG=Googl +e+Search" ); $req->content_type('application/x-www-form-urlencoded'); my $res = $ua->request($req); my $data; if ( $res->is_success ) { $data = $res->content; } else { print $res->status_line; } my @links = $data =~ m/\<a href(.*)\<\/a\>/gs; foreach my $link (@links) { # if ( $link =~ /google/i ) { # next; # } # else { print $link . "this matched\n"; # } }

In reply to matching links in a web request by semio

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, details, 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, summary, 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.