[Tutor] Problems sending POST data

Alex Krycek agent.krycek at gmail.com
Fri May 2 00:02:15 CEST 2008


Hello all,

I've been trying to send POST data to this library database with Python's
urllib, but I can't get it to work.

The website is
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?getLimitedTerms+2307(although
the session expires after a short period of time. So it's better
to first go to denverlibrary.org and then navigate to the advanced search
page).

This is the script that I used:

###################################################################
import urllib

queryString =
"database=10&search1=%2F%2Fw&terms1=&bool1=and&search2=%2F%2Fn&terms2=&bool2=and&search3=%2F%2Ftw%2F&terms3=nanking&bool3=and&search4=%2F%2Fsd%2F&terms4=&bool4=and&search5=%2F%2Fed%2F&terms5=&spellcheck=false&keywords1=qdvds&keywords2=--none--&datelimit=%3E&year1=&year2=&limiter_count=3&branch=&Search=Search&Available=yes"

url = "
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?customSearchFinish+17410"

print urllib.urlopen(url, queryString).read()
###################################################################

However, whenever I run the script I receive the page I was on (Advanced
Search page) again. I'd like to get the page with the search results. This
is what I got from livehttpheaders when I initiated a search from the
website:

###################################################################
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?customSearchFinish+17410

POST /cgi-bin/cw_cgi?customSearchFinish+17410 HTTP/1.1
Host: catalog.denverlibrary.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5)
Gecko/2008032620 Firefox/3.0b5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer:
http://catalog.denverlibrary.org/cgi-bin/cw_cgi?getLimitedTerms+17410
Cookie: __utma=109436176.390208191.1209600128.1209671991.1209676393.6;
__utmz=109436176.1209600128.1.1.utmccn=(referral)|utmcsr=
catalog.denverlibrary.org|utmcct=/cgi-bin/cw_cgi|utmcmd=referral;
__utma=125080728.808666458.1209606982.1209606982.1209606982.1;
__utmz=125080728.1209606982.1.1.utmccn=(referral)|utmcsr=denverlibrary.org|utmcct=/catalogs/index.html|utmcmd=referral;
__utmc=109436176; __utmb=109436176
Content-Type: application/x-www-form-urlencoded
Content-Length: 322
database=10&search1=%2F%2Fw&terms1=&bool1=and&search2=%2F%2Fn&terms2=&bool2=and&search3=%2F%2Ftw%2F&terms3=nanking&bool3=and&search4=%2F%2Fsd%2F&terms4=&bool4=and&search5=%2F%2Fed%2F&terms5=&spellcheck=false&keywords1=qdvds&keywords2=--none--&datelimit=%3E&year1=&year2=&limiter_count=3&branch=&Search=Search&Available=yes

HTTP/1.x 302 Found
Date: Thu, 01 May 2008 21:13:54 GMT
Server: Apache/2.2.0 (Unix) DAV/2 mod_ssl/2.2.0 OpenSSL/0.9.8b PHP/5.1.6
JRun/4.0
Location:
http://catalog.denverlibrary.org:80/cgi-bin/cw_cgi?resultsScreen+17410+1+1+0
Content-Length: 260
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
###################################################################

I'd appreciate any suggestions. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080501/67090f04/attachment.htm>


More information about the Tutor mailing list