v2ex自动签到

已失效

代码

#-*- coding=utf-8 -*-
import requests
from bs4 import BeautifulSoup
import time
import random
import re

username = 'username'
password = 'password'

loginUrl = 'https://www.v2ex.com/signin'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
    'referer': 'https://www.v2ex.com/signin'
}
s = requests.Session()
loginRes = s.get(loginUrl, headers=headers)
soup = BeautifulSoup(loginRes.text, 'lxml')
inputs = soup.find_all('input')
params = {
    soup.find_all('input', {'class': 'sl'})[0].attrs['name']: username,
    soup.find_all('input', {'class': 'sl'})[1].attrs['name']: password,
    'once': soup.find('input', {'name': 'once'}).attrs['value'],
    'next': '/'
}
s.post(loginUrl, params, headers=headers)
dailyUrl = 'https://www.v2ex.com/mission/daily'
res2 = s.get(dailyUrl, headers = headers)
qiandao=re.findall("location.href = '(.*?)'",res2.text)[0]
if s.get('https://www.v2ex.com' + qiandao, headers = headers):
    print u'签到成功'
else:
    print u'签到失败'

crontab定时

0 10 * * * python /root/v2ex.py

依赖库

需要安装 requests, BeautifulSoup 库,使用pip安装

pip install requests
pip install beautifulsoup