python模拟登陆智联招聘

#!/usr/bin/python
#coding=utf8
import urllib
import urllib2
import cookielib
import re
import json
import hashlib
import binascii
import time
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

cj = cookielib.LWPCookieJar()
cookie_support = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)


postdata = {
    'CheckCode': 'xxxx',
    'LoginName': 'xxxx',
    'Password':'xxxxx',
    'Submit': ''
}

postdata = urllib.urlencode(postdata)
print postdata
headers = {
    'User-Agent':'Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20100101 Firefox/8.0',
    'Content-Type':    'application/x-www-form-urlencoded',
    'Referer':'http://rd2.zhaopin.com/portal/myrd/regnew.asp?za=2',
    'Content-Length':'67',
    'Cookie':'xxxxxx'
}

url='https://passport.zhaopin.com/org/login'
req = urllib2.Request(
    url = url,
        data = postdata,
        headers = headers
)
result = urllib2.urlopen(req).read();

print result
p = re.compile('window.location.href = "(.*?)"')
url= p.search(result).group(1)
print url



登陆前使用firebug取出cookie和验证码放到相应的位置即可


你可能感兴趣的:(python模拟登陆智联招聘)