Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LWP

Status
Not open for further replies.

mike101

Programmer
Joined
Jul 20, 2001
Messages
169
Location
US
I need to learn LWP so that I can go to an html page and have it look for certain html codes in the source and when it finds it to print what is after it until some other html commands. For example &quot;<a href=' I would want it to get say... the part how do I do this using one of the LWP Modules? Once I see one or 2 examples I will understans.
Thanks.
 
This approach will not let you time-out the 'get'. If you want more control over the 'get' you'll need to use some of the other LWP tricks. Sorry, my examples of those are on my PC at work. If you need them, I can get them monday.

Code:
#!/usr/local/bin/perl 

use LWP::Simple;

$uri = '[URL unfurl="true"]http://www.perl.com';[/URL]
$page_content = get($uri);

# use pattern matching to see if the page contains 'body' tags.
if ($page_content =~ /<body>.*?<\/body>/i )
{
print &quot;Page, $uri, has body tags and maybe something inbtween them.\n&quot;;
}

I think that will work.
HTH


keep the rudder amid ship and beware the odd typo
 
Can you tell me how to make what is in between those body tags, for example, variables so I can use them variables to print it or change it around. Thanks. This will help me a ton. And if you could e-mail me those examples when you get to work on Monday that will be great because I will be leaving town on Wednesday for 2 weeks.
 
wrap the part of your pattern that you want to catch in parens, and if you get a match the part in parens will go into $1. The second set of parens would go into $2, third into $3, and so on.

if ($page_content =~ /<body>(.*?)<\/body>/i )
{
my $body = $1;
print &quot;here is the stuff between the body tags.\n&quot;;
print &quot;$body\n\n&quot;;
}

HTH


keep the rudder amid ship and beware the odd typo
 
THANK YOU SO MUCH!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top