|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Perl query posting script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|