Link to home
Avatar of rosa545
rosa545

asked on

perl request

guys i want a script that could load url from file and make a request to each link individually


m using the following code to open file and read all url form it so please tell me how can make request to each link one by one
#!/usr/local/bin/perl
 open (links, 'links.txt');
 while (<links>) {
 	chomp;
 	print "$_\n";
 }
 close (links);

Open in new window

SOLUTION
Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mcolomera
mcolomera

use this code after the chomp function:

 require HTTP::Request;
 $request = HTTP::Request->new(GET => 'http://www.example.com/');

bye
 
use LWP::UserAgent;
$ua = LWP::UserAgent->new;

my $req = HTTP::Request->new(POST=>$url);
$req->content_type('application/x-www-form-urlencoded');
$req->content("text=$text&login=gorynych&passwd=gorynych");
my $res = $ua->request($req);

print "Content-type: text/html\\n\\n";
print $res->content;

Open in new window

Avatar of rosa545

ASKER

PILSON66

how will this open a txt file and request to each url???
Avatar of rosa545

ASKER

will this work?? like following steps


1.open a txt file
2.make request to each link
3.match the content of link if content is desired then add a new text file and post that requested url to the new file
4.go to next link and loop 2 and 3 again for each link in the txt file opened in 1
use LWP::UserAgent;
$ua = LWP::UserAgent->new;


 open (links, 'links.txt');
 while (<links>) {
 	chomp;
 	print "$_\n";
 }
 close (links);


my $req = HTTP::Request->new(POST=>$url);
$req->content_type('application/x-www-form-urlencoded');
$req->content("text=$text&login=gorynych&passwd=gorynych");
my $res = $ua->request($req);

print "Content-type: text/html\\n\\n";
print $res->content;

Open in new window

ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of rosa545

ASKER

this will make request to each link???
Avatar of rosa545

ASKER

and how to use post if i want to for each link???
yes, one request for each link.
You can change request method:

#!/usr/local/bin/perl
require HTTP::Request;

 open (links, 'links.txt');
 while (<links>) {
       chomp;
       $request = HTTP::Request->new(POST =>"$_\n" );
 }
 close (links);

More info:
http://search.cpan.org/~gaas/HTTP-Message-6.02/lib/HTTP/Request.pm
Avatar of rosa545

ASKER

not working for me i have added links in links.txt the code does not works and i want to add some data in filed

name=
city=


the code is not working
#!/usr/local/bin/perl
require HTTP::Request;

 open (links, 'links.txt');
 while (<links>) {
       chomp;
       $request = HTTP::Request->new(POST =>"$_\n" );
 }
 close (links);

Open in new window

Avatar of rosa545

ASKER

no1 knows how to do that?
Avatar of rosa545

ASKER

i want something like this



1.Open a text file containing urls
2.send a web request to all url one by one (post some data also in field of "name=" )
3.check the response of the sent page and if it fulfills condition open new text file and add that url to that new made file
4.loop the whole code for all urls in the txt file opened in 1
Avatar of Suhas .
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.