# -*- coding:utf8 -*-
import sys
import urllib, urllib2
def login(username, password):
url = '
http://www.v2ex.com/signin' param = {
'u': username,
'p': password,
'once':48203,
'next':'/'
}
data = urllib.urlencode(param)
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ko;q=0.2,ja;q=0.2',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Content-Length': len(data),
'Content-Type': 'application/x-www-form-urlencoded',
'Host': '
www.v2ex.com',
'Origin': '
http://www.v2ex.com',
'Referer': '
http://www.v2ex.com/signin',
'Upgrade-Insecure-Requests': 1,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36'
}
response = urllib2.urlopen(url, data, timeout=10)
the_page = response.read()
print the_page
if __name__ == '__main__':
username = 'xu123456789'
password = '***********'
login(username, password)