forked from dytttf/antispider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_down_douban.py
53 lines (46 loc) · 1.49 KB
/
test_down_douban.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
#coding:utf-8
import os
import re
import time
import random
import json
import requests
def get_cookie():
import string
import random
import time
base = string.letters + string.digits + "_"
bid = "".join(random.sample(base, 11))
cookie = 'bid=%s; ac="%s"'%(bid, int(time.time()))
return cookie
proxies = {"http":"http://175.151.205.202:808"}
LOGINURL = 'http://www.pss-system.gov.cn/sipopublicsearch/search/executeGeneralSearch-returnResultOnly.shtml'
LOGINURL = 'https://www.douban.com/location/world/'
#assert 1==2
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0",
"Cookie":get_cookie(),
"Host":"douban.com",
"Connection":"keep-alive",
"Accept-Encoding":"gzip, deflate, br",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cache-Control":"max-age=0",
#"Cache-Control":"max-age=0",
#"X-Forward-For":"222.130.132.163",
}
session = requests.Session()
resp = session.get(LOGINURL, headers=headers)
print resp.headers
print resp
print session.cookies
resp.encoding = 'utf8'
text = resp.text
if re.search("window\.location\.href=\"https", text):
url = re.search("window\.location\.href=\"([^;]+);", text).group(1)
print url
url = url.replace('"+d+"', 'navigator.platform|navigator.userAgent|navigator.vendor')
#print text
print len(text)
with open("aaa.html",'w') as f:
f.write(text.encode('utf8'))
print resp.url