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

Perl

Avatar of undefined
Last Comment
Suhas .

8/22/2022 - Mon
SOLUTION
Bryan Butler

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
mcolomera

use this code after the chomp function:

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

bye
pilson66

 
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

rosa545

ASKER
PILSON66

how will this open a txt file and request to each url???
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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
mcolomera

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
rosa545

ASKER
this will make request to each link???
rosa545

ASKER
and how to use post if i want to for each link???
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
mcolomera

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
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

rosa545

ASKER
no1 knows how to do that?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
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
Suhas .

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.