Created
December 25, 2011 08:41
-
-
Save shwangdev/1518898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Time-stamp: <2011-12-25 16:34:05 Sunday by devil> | |
# @version 1.0 | |
# @author ahei | |
import httplib | |
import os.path | |
import urllib2 | |
import cookielib | |
import urllib | |
import sys | |
# class AutoUpdate(Object) : | |
# self.cookiefile = 'cookies.lwp' | |
# self.cj = CookieJar() # cookie jar | |
# self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
# import os.path | |
# import urllib2 | |
# import cookielib | |
COOKIEFILE = 'cookies.lwp' | |
urlopen = urllib2.urlopen | |
Request = urllib2.Request | |
cj = cookielib.LWPCookieJar() | |
if os.path.isfile(COOKIEFILE): | |
cj.load(COOKIEFILE) | |
if cookielib is not None: | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
urllib2.install_opener(opener) | |
theurl = 'http://10.64.66.127:8080/officescan/console/html/cgi/cgiChkMasterPwd.exe?id=0010' | |
txdata = None | |
txheaders = {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; BRI/2; MS-RTC LM 8)'} | |
try: | |
req = Request(theurl, txdata, txheaders) | |
handle = urlopen(req) | |
except IOError, e: | |
print 'We failed to open "%s".' % theurl | |
if hasattr(e, 'code'): | |
print 'We failed with error code - %s.' % e.code | |
elif hasattr(e, 'reason'): | |
print "The error object has the following 'reason' attribute :" | |
print e.reason | |
print "This usually means the server doesn't exist," | |
print "is down, or we don't have an internet connection." | |
sys.exit() | |
else: | |
print 'Here are the headers of the page :' | |
print handle.info() | |
# handle.read() returns the page | |
# handle.geturl() returns the true url of the page fetched | |
# (in case urlopen has followed any redirects, which it sometimes does) | |
if cj is None: | |
print "We don't have a cookie library available - sorry." | |
print "I can't show you any cookies." | |
else: | |
print 'These are the cookies we have received so far :' | |
for index, cookie in enumerate(cj): | |
print index, ' : ', cookie | |
cj.save(COOKIEFILE) # save the cookies again | |
html = handle.read() | |
open('s1.html','w').write(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment