-
-
Save anonymous/99ef5fb95bd8e4c72f1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
import requests as rq | |
import random as rd | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
headers = { | |
'Connection': 'keep-alive', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36', | |
} | |
page_idx = 1 | |
query_dict = {'fid':-7, 'page':page_idx} | |
url_head = 'http://bbs.ngacn.cc/thread.php' | |
r = rq.get(url_head, params = query_dict) | |
#r = rq.get(url_head, params = query_dict, headers = headers) | |
print 'First init OK.' | |
r.encoding = 'gbk' | |
f = open('test_first.html', 'w') | |
f.write(r.text) | |
f.close() | |
headers = { | |
'Host': 'bbs.ngacn.cc', | |
'Connection': 'keep-alive', | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', | |
'Upgrade-Insecure-Requests': '1', | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36', | |
'Referer': 'http://bbs.ngacn.cc/thread.php?fid=-7&page=1', | |
'Accept-Encoding': 'gzip, deflate, sdch', | |
'Accept-Language': 'zh-CN,zh;q=0.8' | |
} | |
rand = rd.randint(1, 999) | |
query_dict = {'fid':-7, 'page':page_idx, 'rand': rand} | |
cookies = r.cookies | |
print cookies | |
headers = r.headers | |
r = rq.get(url_head, params = query_dict, headers = headers, cookies = cookies) | |
print r.url | |
r.encoding = 'gbk' | |
#print r.text | |
f = open('test.html', 'w') | |
f.write(r.text) | |
f.close() | |
#print r.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment