Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Parse what's in a URL

Reply
Thread Tools

Parse what's in a URL

 
 
donfanning@msn.com
Guest
Posts: n/a
 
      09-26-2005
Is there a way using perl to take a URL, submit it, then parse the
resulting url it returns after the page pulls? Like for submitting a
query to a database and getting a status code in return (success,
failure, reason, etc..)

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-26-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Is there a way using perl to take a URL, submit it, then parse the
> resulting url it returns after the page pulls? Like for submitting a
> query to a database and getting a status code in return (success,
> failure, reason, etc..)


If you want the resulting _content_, this FAQ entry is applicable:

perldoc -q "HTML file"

If you are after only the HTTP status, this may help:

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
print $response->status_line;

In general, please make yourself comfortable with the LWP family of CPAN
modules.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Eric Bohlman
Guest
Posts: n/a
 
      09-26-2005
(E-Mail Removed) wrote in news:1127773035.855380.237430
@z14g2000cwz.googlegroups.com:

> Is there a way using perl to take a URL, submit it, then parse the
> resulting url it returns after the page pulls? Like for submitting a
> query to a database and getting a status code in return (success,
> failure, reason, etc..)


Your terminology is a bit confused here; what an HTTP request sent to a
particular URL returns is not a URL, but a response. The response may be
just a status code for the HTTP request, or a resource like an HTML page
(which may contain status codes not related to HTTP, such as database query
results). I assume you want to parse the returned document. If so, you
probably want to look into WWW::Mechanize.
 
Reply With Quote
 
donfanning@msn.com
Guest
Posts: n/a
 
      09-26-2005
I was thinking more along the lines of HTML::SimpleLinkExtor where I
submit it a link. The remote page needs time to pull from a database
and it spits out information in the URL which I would like to parse
out.

 
Reply With Quote
 
donfanning@msn.com
Guest
Posts: n/a
 
      09-26-2005
Nope... The returned document doesn't matter. I can use the example
that Gunter listed to pull 404's and stuff. The information I'm
looking for is embedded in the URL.

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-26-2005
(E-Mail Removed) wrote:
> I was thinking more along the lines of HTML::SimpleLinkExtor where I
> submit it a link. The remote page needs time to pull from a database
> and it spits out information in the URL which I would like to parse
> out.


Now I'm confused. HTML::SimpleLinkExtor extracts links from an HTML
document, while you said in your reply to Eric that the returned
document doesn't matter. Either you don't explain accurately enough what
it is you want, or I'm unusually stupid.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-26-2005
(E-Mail Removed) wrote in news:1127776150.886370.189270
@z14g2000cwz.googlegroups.com:

[ Please quote an appropriate amount of context when you reply ]

> Nope... The returned document doesn't matter. I can use the example
> that Gunter


s/Gunter/Gunnar

> listed to pull 404's and stuff. The information I'm
> looking for is embedded in the URL.


You want to parse the URL that you use to invoke the script? I am a
little confused. Don't you know how you constructed the URL?

In any case, there probably is an answer to your question in the LWP
documentation, I am just not sure what the question is.

http://search.cpan.org/~gaas/libwww-...803/lib/LWP.pm
http://search.cpan.org/~gaas/libwww-perl-
5.803/lib/LWP.pm#The_Response_Object

http://search.cpan.org/~rse/lcwa-1.0...lib/URI/URL.pm

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
donfanning@msn.com
Guest
Posts: n/a
 
      09-26-2005
My apologies for not clarifying:

So if I take a URL say http://www.test.com/&search=123 and submit it
The server will respond back with a page but the url will have the
information I am looking for ie:
http://www.test.com/&result=0&status=true or something to that nature.

What I want is the Result=0 and Status=True portion of the URL that it
returns.

My apologies on your name Gunnar. I always get icelandic names wrong.


 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-27-2005
(E-Mail Removed) wrote in news:1127779163.028178.101840
@g47g2000cwa.googlegroups.com:

> My apologies for not clarifying:


[ Please quote an appropriate amount of context when replying ]

> So if I take a URL say http://www.test.com/&search=123 and submit it
> The server will respond back with a page but the url will have the
> information I am looking for ie:
> http://www.test.com/&result=0&status=true or something to that nature.


Then you should read the LWP docs.

> What I want is the Result=0 and Status=True portion of the URL that it
> returns.


Go ahead and read the docs. If you hit a snag, post some code. Before
posting code, read the posting guidelines.

> My apologies on your name Gunnar. I always get icelandic names wrong.
>


He is from Sweden, though. (Gunnar: I don't know if you care, and
apologies if I am overstepping my bounds here).

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      09-27-2005

"A. Sinan Unur" <(E-Mail Removed)> wrote in message
news:Xns96DDD0A353291asu1cornelledu@127.0.0.1...
> (E-Mail Removed) wrote in news:1127779163.028178.101840
> @g47g2000cwa.googlegroups.com:
>
>
>> My apologies on your name Gunnar. I always get icelandic names wrong.
>>

>
> He is from Sweden, though. (Gunnar: I don't know if you care, and
> apologies if I am overstepping my bounds here).
>


<quote>
From the Old Norse name Gunnarr which was derived from the elements gunnr
"war" and arr "warrior". It is thus a cognate of GÜNTHER. Gunnar was a
character in Norse legend, the husband of Brynhild.
</quote>

I'm sure considering its history there are many people in Iceland with
Nordic names. I have nothing else to add, but just thought it would be fun
to join in this totally off-topic discussion of Gunnar's name... : )

Matt


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
Parse text box into url firstcustomer@gmail.com HTML 4 03-17-2006 03:44 PM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
URL - substitution of a correct URL by a GUID like URL in favorites. Just D. ASP .Net Mobile 0 08-11-2004 04:26 PM
redirect URL's, return URL's, and URL Parameters Jon paugh ASP .Net 1 07-10-2004 05:29 AM



Advertisments