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
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);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
ASKER
PILSON66
how will this open a txt file and request to each url???
how will this open a txt file and request to each url???
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
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this will make request to each link???
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
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
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
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);
ASKER
no1 knows how to do that?
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
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
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
require HTTP::Request;
$request = HTTP::Request->new(GET => 'http://www.example.com/');
bye