Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Process a HTML file to get information from it.

by JediWizard (Deacon)
on Dec 11, 2006 at 17:10 UTC ( #589088=note: print w/replies, xml ) Need Help??


in reply to Process a HTML file to get information from it.

Try using <code> tags around your html to prevent it from rendering.

Otherwise, I think you need something like this:

m/<a[^>]* # an anchor tag href= # the Href in the anchor (["'])((?:(?!\1).)*)\1 # the value in the href [^>]*> # anything to the end of the anchor [^<>]* # the content in the anchor tag <\/a> # the end of the anchor (?:\s|<[^>]*>)+ # any whitespace or html tags (\d{9}) # the 9 digit number /isxm; my $href = $2; my $number = $3;

Update:

my $re = qr/<a[^>]* # an anchor tag href= # the Href in the anchor (["'])((?:(?!\1).)*)\1 # the value in the href [^>]*> # anything to the end of the anchor [^<>]* # the content in the anchor tag <\/a> # the end of the anchor (?:\s|<[^>]*>)+ # any whitespace or html tags (\d{9}) # the 9 digit number /isxm; my $string = do{local $/; <DATA>}; while($string =~ m/$re/g){ my $href = $2; my $number = $3; print "$number - $href\n"; } __DATA__ <a name="a"></a> <h2>A</h2> <table border="0" cellpadding="0" cellspacing="0" width="1 +00%"> <tr> <td> <table id="a" border="1" bordercolor="#333366" ce +llpadding="5" cellspacing="0" width="100%"> <tr> <td width="33%" class="clsTableBody" valign +="top" id="firstCol"><a href="pdf\c76b834e-36e1-497b-b13e-eba2348dc04 +4.pdf" target="_blank">Abbott, Evelyn</a><br/><span>110136892</span>< +br/><a href="pdf\8a956f66-1c60-48fc-905c-b49d617aa6c5.pdf" target="_b +lank">Agnew, Thomas</a><br/><span>110377660</span><br/></td> <td width="34%" class="clsTableBodyClear" v +align="top" id="secondCol"><a href="pdf\37d3e78b-1adb-458b-9e89-0df78 +0909f08.pdf" target="_blank">Allison, David</a><br/><span>108116112</ +span><br/><a href="pdf\6c0a5bb4-143d-4305-957b-796c8193d07a.pdf" targ +et="_blank">Allison, Gary Owen</a><br/><span>116815754</span><br/></t +d> <td width="33%" class="clsTableBody" valign +="top" id="thirdCol"><a href="pdf\ae8d51e0-005b-44be-84cb-3c9b5733575 +5.pdf" target="_blank">Arsenault, Michael</a><br/><span>108318866</sp +an><br/><a href="pdf\e646f948-f78d-4463-a01d-0261aebf70dc.pdf" target +="_blank">Arsenault, Normand A.</a><br/><span>113069066</span><br/></ +td> </tr> </table> </td> </tr> </table>

Output:

110136892 - pdf\c76b834e-36e1-497b-b13e-eba2348dc04 +4.pdf 110377660 - pdf\8a956f66-1c60-48fc-905c-b49d617aa6c5.pdf 108116112 - pdf\37d3e78b-1adb-458b-9e89-0df78 +0909f08.pdf 116815754 - pdf\6c0a5bb4-143d-4305-957b-796c8193d07a.pdf 108318866 - pdf\ae8d51e0-005b-44be-84cb-3c9b5733575 +5.pdf 113069066 - pdf\e646f948-f78d-4463-a01d-0261aebf70dc.pdf

They say that time changes things, but you actually have to change them yourself.

—Andy Warhol

Replies are listed 'Best First'.
Re^2: Process a HTML file to get information from it.
by Griffler (Novice) on Dec 11, 2006 at 19:11 UTC
    Thanks for the hints!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://589088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2021-06-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (121 votes). Check out past polls.

    Notices?