-
Notifications
You must be signed in to change notification settings - Fork 0
/
acfun.py
64 lines (52 loc) · 1.9 KB
/
acfun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import urllib, urllib2, cookielib, re, time, requests
LOGIN_URL = 'http://passport.acfun.tv/login.aspx'
ACCOUNT = 'YOURACCOUNT'
PWD = 'PASSWORD'
class Acfun(object):
def __init__(self):
self.account = ACCOUNT
self.pwd = PWD
self.login_url = LOGIN_URL
self.cookiefile = 'cookie.txt'
self.html = ''
def login(self):
data_json = {'password':self.pwd, 'username':self.account}
data = urllib.urlencode(data_json)
cookie = cookielib.MozillaCookieJar(self.cookiefile)
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
response = opener.open(self.login_url, data)
cookie.save(ignore_discard=True, ignore_expires=True)
#target_url = 'http://www.acfun.tv/member/#area=profile'
#result = opener.open(target_url)
#self.html = result.read()
def getContent(self):
pattern = re.compile(r'<div id="mainer-inner">.*?class="name">(.*?)</a>.*?', re.S)
result = re.findall(pattern, self.html)
print result[0]
def signin(self):
cookie = cookielib.MozillaCookieJar()
cookie.load(self.cookiefile, ignore_discard=True, ignore_expires=True)
times = int(time.time()*1000)
url = 'http://www.acfun.tv/webapi/record/actions/signin?channel=0&date='+str(times)
#url = 'http://www.acfun.tv/member/checkin.aspx'
headers = {
"Host": "www.acfun.tv",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Referer": "http://www.acfun.tv/member/",
}
data = ''
data = urllib.urlencode(data)
req = urllib2.Request(url, headers=headers)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
#opener.addheaders = [('Referer', 'http://www.acfun.tv/member/')]
response = opener.open(req, data)
print response.read()
if __name__ == "__main__":
acfun = Acfun()
acfun.login()
#acfun.getContent()
acfun.signin()