问题遇到的现象和发生背景
爬取集思录可转债信息,绝大部分标签都能读取,唯独个别标签一直报错
以下是网页标签
data: [,…]
[0 … 99]
0: {bond_id: "127057", bond_nm: "盘龙转债", bond_py: "plzz", price: 100, increase_rt: 0, stock_id: "002864",…}
adj_cnt: 0
adj_scnt: 0
adjust_condition: "15/30 85%"
adjusted: "N"
bond_id: "127057"
bond_nm: "盘龙转债"
bond_nm_tip: ""
bond_py: "plzz"
bond_value: null
btype: "C"
convert_amt_ratio: 7.3
convert_cd_tip: "未到转股期;2022-09-09 开始转股"
convert_dt: 157
convert_price: 26.59
convert_price_tips: ""
convert_price_valid: "Y"
问题相关代码,请勿粘贴截图
response = requests.get(url_zhuanzhai, headers=headers)
json_data = response.json()
data_list2 = json_data['data']
for data_get in data_list2:
data1 = data_get['bond_id']
data2 = data_get['bond_nm']
data3 = data_get['premium_rt']
data4 = data_get['volume']
data5 = data_get['bond_nm_tip']
运行结果及报错内容
Traceback (most recent call last):
File "D:/fund project/套利提醒器1.1.py", line 338, in
run()
File "D:/fund project/套利提醒器1.1.py", line 56, in run
if get_ConvertibleBond() != "":
File "D:/fund project/套利提醒器1.1.py", line 278, in get_ConvertibleBond
data2 = data_get['bond_nm']
KeyError: 'bond_nm'
我想要达到的结果
bond_id,premium_rt,volume都能正常读取,但bond_nm和bond_nm_tip总是KeyError,请指教