Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 9th, 2002, 10:31 AM
tmoloshok tmoloshok is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 1 tmoloshok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Perl query posting script

I have been sending simple queries over the internet to various database servers using coding like:

use IO::Socket;
$query = "/htbin-post/Entrez/query?db=m&form=4&term=$word1&$word2"."[all]"."&dopt=b&dispmax=50&tool=IGM&save=m";
$EOL = "\015\012";
$BLANK = $EOL x 2;
$remote = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => "www.ncbi.nlm.nih.gov",
PeerPort => "http(80)",
);
unless ($remote) { die "cannot connect to http daemon on host" }
$remote->autoflush(1);
print $remote "GET $query HTTP/1.0" . "$BLANK";

Such scripting doesn't work for sites expecting form encoded querying. I capture query sessions through my port to see what is bing sent but don't know how to use the information in my scripts. An example is:
Send 350 bytes on stream 24.
POST /tigr-scripts/magic/r4.pl HTTP/1.1
Host: pga.tigr.org
Accept: */*
Accept-Language: en
Connection: Keep-Alive
Referer: URL
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
UA-OS: MacOS
UA-CPU: PPC
Content-type: application/x-www-form-urlencoded
Extension: Security/Remote-Passphrase

Send 207 bytes on stream 24.
Content-length: 184

species=1&gblist=AA409614+AA409620+AA409627&Get+TC=Get+TC&.cgifields=species

Receive 162 bytes on stream 24.
HTTP/1.1 200 OK
.
.
.
Can anyone tell me how to script such a query, i want to take the resulting page and parse information out of it into report tables.
thanks,
tom

Reply With Quote
  #2  
Old January 9th, 2002, 10:28 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
This should probably be moved to the perl forum. . .

Anything having to do with posting data to / getting data from the web is best done with LWP and the LWP suite of modules like LWP::Simple, LWP::UserAgent. It's quite stunning what you can do with these modules when you dig into them.

Do a google search for lwpcook (or if you have perl 5.6 .x and are on a *nix system, type "man lwpcook" or "perldoc lwpcook"), the excellent intro to using LWP.

Doing this with IO::Socket is MUCH more difficult than using LWP, because LWP will take care of a lot of the lower-level stuff for you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Perl query posting script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway