-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPdfListGet.py
More file actions
103 lines (90 loc) · 3.58 KB
/
Copy pathPdfListGet.py
File metadata and controls
103 lines (90 loc) · 3.58 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3
from urllib import parse
import http.client
import json
import socket
import os
class PdfListGet:
def __init__(self, orgId, code, name):
self.orgId = orgId
self.code = code
self.name = name
self.data = []
def getPdfList(self, keylist, ban = []):
for key in keylist:
self.getPdfListByKey(key, ban)
print("共获取到", len(self.data), "个链接")
return self.data
def getPdfListByKey(self, key, ban):
print("正在搜索PDF链接 --- " + self.name + " --- " + key)
print("正在获取PDF链接 --- " + self.name + " --- 沪市")
self.httpConnect("sse", "shmb", "沪市", key)
self.jsonDecode(ban)
print("正在获取PDF链接 --- " + self.name + " --- 深市")
self.httpConnect("szse", "sz", "深市", key)
self.jsonDecode(ban)
def jsonDecode(self, ban):
if self.jsonMessage != None:
data = json.loads(self.jsonMessage)
if data["totalAnnouncement"] > 50:
print("Warning: 总搜索数大于50,未下载完全")
announ = data["announcements"]
for a in announ:
title = a["announcementTitle"]
isBan = False
for b in ban:
if title.find(b) != -1:
isBan = True # 查找到禁用字符串
break
if isBan:
continue # 跳过该文件
info = []
info.append(a["adjunctUrl"])
info.append(a["announcementTime"])
info.append(a["announcementTitle"])
self.data.append(info)
# 创建http连接 获取Json字符串
# ! 去掉 'accept-encoding': "gzip, deflate", 解除加密
# ! 去掉 'content-length' 避免计算长度
def httpConnect(self, column, plate, platename, key):
conn = http.client.HTTPConnection("www.cninfo.com.cn")
payload = (
"pageNum=1&pageSize=50&tabName=fulltext&column="
+ column
+ "&stock="
+ self.code
+ "%2C"
+ self.orgId
+ "&searchkey=" + parse.quote(key) + "%3B&secid=&plate="
+ plate
+ "&category=&trade=&seDate=2000-01-01+~+2099-03-01"
)
headers = {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6",
"connection": "keep-alive",
"host": "www.cninfo.com.cn",
"origin": "http://www.cninfo.com.cn",
"referer": "http://www.cninfo.com.cn/new/disclosure/stock?orgId="
+ self.orgId
+ "&stockCode="
+ self.code,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
"x-requested-with": "XMLHttpRequest",
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache",
}
conn.request("POST", "/new/hisAnnouncement/query", payload, headers)
try:
res = conn.getresponse()
data = res.read()
self.jsonMessage = data.decode("utf-8")
return
except ConnectionResetError:
print("注意: Http连接错误," + self.name + "," + platename)
os.system("pause")
self.jsonMessage = None
def main():
print(parse.quote("重大事项"))
if __name__ == "__main__":
main()