-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathgsxt_mobile.py
50 lines (43 loc) · 1.72 KB
/
gsxt_mobile.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
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
'''通过国家企业信用信息公示系统(www.gsxt.gov.cn) Mobile App HTTP API 查询企业信息'''
import json
import requests
URL = 'http://yd.gsxt.gov.cn/QuerySummary'
MOBILE_ACTION = 'entSearch'
TOPIC = 1
PAGE_NUM = 1
PAGE_SIZE = 10
USER_ID = 'id001'
USER_IP = '192.168.0.1'
USER_AGENT = 'Mozilla/5.0 (Linux; Android 4.4.2; vivo Y28L Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 Html5Plus/1.0'
ACCEPT_LANGUAGE = 'zh-CN,en-US;q=0.8'
XRW = 'com.zongjucredit'
ORIGIN = 'file://'
CHARSET = 'application/x-www-form-urlencoded; charset=UTF-8'
def query(keyword):
'''main entry'''
_data = [('mobileAction', MOBILE_ACTION),
('keywords', keyword),
('topic', TOPIC),
('pageNum', PAGE_NUM),
('pageSize', PAGE_SIZE),
('userID', USER_ID),
('userIP', USER_IP)]
_headers = {'User-Agent': USER_AGENT,
'Accept-Language': ACCEPT_LANGUAGE,
'X-Requested-With': XRW,
'Origin': ORIGIN,
'Content-Type': CHARSET}
_response = requests.post(URL, data=_data, headers=_headers)
print(_response.status_code)
if _response.status_code == 200:
_content = _response.json()
print(len(_content))
print(json.dumps(_content, indent=2, sort_keys=True, ensure_ascii=False))
with open(keyword + str(len(_content)) + '.txt', 'w', encoding='utf-8') as _f:
json.dump(_content, _f, indent=2, sort_keys=True, ensure_ascii=False)
else:
print('request fail')
if __name__ == "__main__":
query('腾讯科技')