成功了,记录一下问题
1,安装第三方库,要在cmd下切换到到pip命令行下才行
2,v2ex登陆时要用https
# coding=utf-8
import requests
from bs4 import BeautifulSoup as bs
s = requests.Session()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Origin': 'http://www.v2ex.com',
'Referer': 'http://www.v2ex.com/signin',
'Host': 'www.v2ex.com',
}
r = s.get('http://www.v2ex.com/signin', headers=headers)
soup = bs(r.content)
once = soup.find('input', {'name': 'once'})['value']
print once
login_data = {'u': 'Registering', 'p': '3982895898', 'once': once, 'next': '/'}
s.post('https://www.v2ex.com/signin', login_data, headers=headers)
f = s.get('https://www.v2ex.com/settings', headers=headers)
print f.content