[Python] 纯文本查看 复制代码
import requests
import json
import time
import re
import pandas as pd
def bce_all():
url = 'http://www.bse.cn/newShareController/infoResult.do?callback=jQuery331_' + str(int(time.time() * 1000))
headers = {
"Referer": "http: //www.bse.cn/newshare/listofissues.html",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"
}
form = [
("statetypes[]", "0"),
("page", "0"),
("companyCode", ''),
("isNewThree", "1"),
("sortfield", "purchaseDate"),
("sorttype", "desc"),
("keyword", ''),
("needFields[]", "id"),
("needFields[]", "stockCode"),
("needFields[]", "stockName"),
("needFields[]", "initialIssueAmount"),
("needFields[]", "enquiryType"),
("needFields[]", "issuePrice"),
("needFields[]", "peRatio"),
("needFields[]", "purchaseDate"),
("needFields[]", "issueResultDate"),
("needFields[]", "enterPremiumDate"),
]
response = requests.post(url, headers=headers, data=form)
a = re.findall(r'\[{.*}\]', response.text)
if a:
b = json.loads(a[0])[0]['listInfo']['content']
data = []
for x in b:
if x['enterPremiumDate']:
data.append({"代码": x['stockCode'],
"简称": x['stockName'],
"发行量": x['initialIssueAmount'],
"发行价格": x['issuePrice'],
"市盈率": x['peRatio'],
"申购日": time.strftime("%Y-%m-%d", time.localtime(x['purchaseDate']['time'] / 1000)),
"上市日": time.strftime("%Y-%m-%d", time.localtime(x['enterPremiumDate']['time'] / 1000)),
})
else:
data.append({"代码": x['stockCode'],
"简称": x['stockName'],
"发行量": x['initialIssueAmount'],
"发行价格": x['issuePrice'],
"市盈率": x['peRatio'],
"申购日": time.strftime("%Y-%m-%d", time.localtime(x['purchaseDate']['time'] / 1000)),
"上市日": ' ------ ',
})
else:
print('bad')
return data
if __name__ == '__main__':
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
data = pd.DataFrame(bce_all()[:10])
data
代码 简称 发行量 发行价格 市盈率 申购日 上市日
0 871245 威博液压 8478261 9.68 18.59 2021-12-22 ------
1 836720 吉冈精密 21030000 10.50 21.67 2021-11-03 2021-11-24
2 836260 中寰股份 8500000 13.45 16.00 2021-11-01 2021-11-15
3 871981 晶赛科技 11878300 18.32 28.41 2021-10-26 2021-11-15
4 831832 科达自控 18000000 13.00 45.34 2021-10-26 2021-11-15
5 833454 同心传动 25000000 3.95 14.90 2021-10-18 2021-11-15
6 870436 大地电气 18000000 8.68 13.21 2021-10-18 2021-11-15
7 832171 志晟信息 14530435 6.80 10.93 2021-10-15 2021-11-15
8 833873 中设咨询 33380000 4.50 27.28 2021-10-15 2021-11-15
9 832089 禾昌聚合 20000000 10.00 16.39 2021-10-11 2021-11-09