homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Read html reponse using perl regular expression
PankajBansal




msg:3934180
 9:29 am on Jun 16, 2009 (gmt 0)

I retrieve an HTML response. I am pasting below the extract of the respone i get

<tr>
<td rowspan="1" valign="top">
</td>
<td rowspan="1" valign="top">2009-06-16 00:26:02
</td>
<td>
Status
</td>
<td>AAA
</td>
<td>BBB
</td>
</tr>

The response is too big, so i just copied the extract of the response . I have to capture the date 2009-06-16 00:26:02 using perl regualr expression, whenever the status changes from AAA to BBB.
In the whole response status AAA is changed to BBB only once.

i tried with
$htmlResponse
= ~ m/^(.*)<td>AAA<\/td><td>BBB<\/td><\/tr>/i

but for no use

Please help

 

mattdw




msg:3934300
 12:52 pm on Jun 16, 2009 (gmt 0)

Looks like since they HTML response is multiple lines, your regex is probably not working because it isn't looking for the newline characters.

You could either try to put in a match for the newlines (\n) or add the 's' modifier with your 'i' modifier at the end, then use the 'match anything' . to catch the newline. Check out this tutorial, it explains this: [anaesthetist.com...]

PankajBansal




msg:3934320
 1:08 pm on Jun 16, 2009 (gmt 0)

hmm i tried but its not working.

mattdw




msg:3934400
 2:46 pm on Jun 16, 2009 (gmt 0)

Got a sample of what you are trying now?

janharders




msg:3934949
 7:49 am on Jun 17, 2009 (gmt 0)

maybe
$string =~ !<td rowspan="1" valign="top">([^<]+)\s*</td>\s*<td>\s*Status\s*</td>\s*<td>AAA\s*</td>\s*<td>BBB\s*</td>!gis

will help. \s is a whitespace, thus it matches linebreaks, tabs or spaces (and more? my memory is bad).

PankajBansal




msg:3935334
 5:02 pm on Jun 17, 2009 (gmt 0)

Thanks everyone
below code worked for me

$htmlResponse=~m/(.*)\s*<\/td>\s*<td>\s*Status\s*<\/td>\s*<td>AAA\s*<\/td>\s*<td>\s*BBB\s*<\/td>/igs

[edited by: PankajBansal at 5:03 pm (utc) on June 17, 2009]

chorny




msg:3955375
 7:09 pm on Jul 19, 2009 (gmt 0)

Good solution is to use HTML::TreeBuilder::XPath

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved