Login Register






[TUT] Perl Searching a webpage [Beginner LVL 5] filter_list
Author
Message
[TUT] Perl Searching a webpage [Beginner LVL 5] #1
hey everyone, another perl tutorial here. This tutorial will be covering how to search a webpage for content. This can be very usful as it can be quickly adapted to find thing's like e.g. my sql error for sql injection.

this tutorial will be showing you if a page contains the text "search".

full code
Code:
use LWP::Simple qw(get); use HTTP::Request; print"--- # Item Finder # ---\n\n\n"; print"Url: "; my $url = <STDIN>; my $content = get $url; die "Unable to find $url" unless defined $content; if ($content =~ "search") { print"Page containes search"; } else { print"search not found"; }

explained.

Code:
use LWP::Simple qw(get); use HTTP::Request;
This simply allows is to use the web and connect to the web. For further detail go to http://forum.whitehatorder.net/showthread.php?tid=233.

Code:
print"--- # Item Finder # ---\n\n\n"; print"Url: ";
print's the text in the quotation marks.

Code:
my $url = <STDIN>;
as explained in my other tutorial $ur is the variable to which <STDIN> / standard input / user input is assigned to.

Code:
my $content = get $url; die "Unable to find $url" unless defined $content;
now we start to cover something new, the get command is a great thing to have as i allows is to look through a page source or retrieve the whole source, so as you can see there are two variable's $content and &url. $url is the input we entered so the webpage we want to search, $content is the results from searching so the first line just says get the content of our URL. The second line says if the page cannot be found then print "Unable to find URL" ignore the other bit as it is not important yet.


Code:
if ($content =~ "search") { print"Page containes search"; } else { print"search not found"; }

as said on another tutorial this just says, if our page source contains the word "search" then print"page contains search" else print"search not found"

thanks for reading hoped this helped you.
[Image: 6caf54.gif]

Reply