Skip to content

Instantly share code, notes, and snippets.

@zhangyangjing
Last active March 5, 2017 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangyangjing/697fd538ea58d884de50717a730eeb1b to your computer and use it in GitHub Desktop.
Save zhangyangjing/697fd538ea58d884de50717a730eeb1b to your computer and use it in GitHub Desktop.
Installing collected packages: requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import requests
from datetime import datetime
def log(text):
print("{}: {}".format(datetime.now().isoformat(), text))
requests.packages.urllib3.disable_warnings()
session = requests.Session()
base_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.71 Safari/537.36 OPR/35.0.2066.23 (Edition beta)',
'Referer': 'https://www.v2ex.com/signin'}
session.headers = base_headers
resp = session.get('https://www.v2ex.com/signin', verify=False)
u, p = re.findall(r'class="sl" name="([0-9A-Za-z]{64})"', resp.text)
once_code = re.search(r'value="(\d+)" name="once"', resp.text).group(1)
data = {u: 'username', p: 'password', 'once': once_code, 'next': '/'}
resp = session.post('https://www.v2ex.com/signin', data)
resp = session.get('https://www.v2ex.com/mission/daily', verify=False)
if u'每日登录奖励已领取' in resp.text:
log('Already got it.')
else:
path = re.search(r'/mission/daily/redeem\?once=\d+', resp.text).group()
resp = session.get('https://www.v2ex.com' + path, verify=False)
log(resp.ok)
@CNMan
Copy link

CNMan commented Aug 29, 2016

8.24开始,签到失败
python v2ex_mission_daily.py
Traceback (most recent call last):
File "v2ex_mission_daily.py", line 29, in
path = re.search(r'/mission/daily/redeem?once=\d+', resp.text).group()
AttributeError: 'NoneType' object has no attribute 'group'

@zhangyangjing
Copy link
Author

已修改

@CNMan
Copy link

CNMan commented Mar 5, 2017

python v2ex_mission_daily.py
  File "v2ex_mission_daily.py", line 1
    Installing collected packages: requests
                       ^
SyntaxError: invalid syntax

注释掉第一行后

python v2ex_mission_daily.py
  File "v2ex_mission_daily.py", line 29
SyntaxError: Non-ASCII character '\xe6' in file v2ex_mission_daily.py on line 29, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

第29行汉字改成unicode编码可以用

if u'\u6bcf\u65e5\u767b\u5f55\u5956\u52b1\u5df2\u9886\u53d6' in resp.text:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment