Mechanze form submission causes 'Assertion Error' in response when .read() is attempted

故事扮演 提交于 2019-12-03 22:42:37

This is the solution that I found:

import mechanize,urllib,ClientForm,cookielib,re,os,time
from BeautifulSoup import BeautifulSoup

cookies = mechanize.CookieJar()
opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
headers = [("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),\
           ("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7"),\
           ("Accept-Encoding","gzip, deflate"),\
           ("Accept-Language","en-us,en;q=0.5"),\
           ("Connection","keep-alive"),\
           ("Host","www.aladin.wrlc.org"),\
           ("Referer","https://www.aladin.wrlc.org/Z-WEB/Aladin?req=db&key=PROXYAUTHlib=8url=http://eebo.chadwyck.com/search"),\
           ("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0")]
opener.addheaders = headers
mechanize.install_opener(opener)
params = urllib.urlencode({'LN':'myLN','BC':'myBC','INST':'myINST',\
                           'req':'db','key':'PROXYAUTH','lib':'8',\
                           'url':'http://eebo.chadwyck.com/search'})
mechanize.urlopen("https://www.aladin.wrlc.org/Z-WEB/PATLogon",params)

Hope this helps someone someday :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!