#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
login_url=r'https://www.v2ex.com/signin'
headers = {
"content-type":"application/x-www-form-urlencoded",
'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': '
https://www.v2ex.com',
'Referer': '
https://www.v2ex.com/signin'
}
userName='pive'
password='******'
s=requests.Session()
res=s.get(login_url,headers=headers)
soup=BeautifulSoup(res.content,"html.parser")
once=soup.find("input",{"name":"once"})["value"]
formUserName=soup.find("input",type="text")["name"]
formPassword=soup.find("input",type="password")["name"]
print(once+"\n"+userName+"\n"+password)
post_data={
formUserName:userName,
formPassword:password,
"once":once,
"next":"/"
}
s.post(login_url,post_data,headers=headers)
f = s.get('https://www.v2ex.com/settings',headers=headers)
with open('v2ex.html',"wb") as v2ex:
v2ex.write(f.content)