It is irrelevant whether or not is PHP. PHP generates HTML and it is the HTML you need to parse. Using Apache's rewrite rules I could generate HTML using perl but make them look like PHP generated output. A certain sort of webmaster might even want to do that to confuse hackers.

WWW::Mechanize may be overkill for your needs and LWP, which the former is built upon, should be adequate. (I think where WWW::Mechanize comes in is where you need to login to a website to see content etc.)

In an ideal world well actually some people think in an ideal world, the web would use YAML or something rather than HTML, but that is a different story...... In an ideal world, all HTML would be valid XHTML. Then you could use XML::LibXML to parse the page and off you go. In practice this is highly unlikely to be the case. You are better off using HTML::TreeBuilder to get you going. Grabbing some code from something similar (but not reuseable) you probably want something like:

require LWP::UserAgent; require HTML::TreeBuilder; my $ua = LWP::UserAgent->new(......); my $response = $ua->get(......); if ($response->is_success) { # get the document from the web my $r = $response->decoded_content; # or whatever my $tidied_doc = HTML::TreeBuilder->new_from_content($r)->as_HTML( +); .................. } else { die $response->status_line; }

The other problem is that if the webpage has any sort of international content it is quite likely to declare itself as being encoded in Latin-1, but to contain a mixture of Latin-1 and unicode characters.


In reply to Re: Parsing Links from .php by SilasTheMonk
in thread Parsing Links from .php by jdetloff

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.