TypeError: export_excel() missing 1 required positional argument: 'item'
麻烦帮忙看一下代码哪里错了。万分感谢!
import json
import pandas as pd
import time
import requests
headers = {
'user-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69',
'referer': 'http://www.cninfo.com.cn/new/commonUrl/pageOfSearch?url=disclosure/list/search&lastPage=index',
'X-Requested-With': 'XMLHttpRequest'
}
for i in range(48):
data = {'column': 'szse',
'pageNum': i+1,
'pageSize': 30,
'tabName': 'fulltext',
'plate': '',
'stock': '',
'searchkey': '并购',
'secid': '',
'category': '',
'trade': '',
'seDate': '2019-12-31~2021-12-31',
'sortName': '',
'sortType': '',
'isHLtitle': 'true'}
d = requests.post('http://www.cninfo.com.cn/new/hisAnnouncement/query', headers=headers, data=data).json()
for item in d['announcements']:
code=item['secCode']
name=item['secName']
title3=item['announcementTitle']
title2=title3.replace('<em>', '')
title=title2.replace('</em>', '')
print(code)
print(name)
print(title)
announcementTime = str(item['announcementTime']) # 发布时间是时间戳,格式要转下
announcementTime = int(announcementTime[0:len(announcementTime) - 3])
announcementTime = time.localtime(announcementTime)
time2=time.strftime("%Y-%m-%d", announcementTime)
url=item['adjunctUrl']
print(time2)
print(url)
print('---------------')
print(item)
def export_excel(item):
pf = pd.DataFrame(list(item)) #将字典列表转换为DataFrame
order = ['code', 'name', 'title', 'url', 'time2'] #指定字段顺序
pf = pf[order]
columns_map={'code': '代码', 'name': '公司简称', 'title': '标题', 'url': '网址', 'time2': '发布时间'} #将列名替换为中文
pf.rename(columns=columns_map, inplace=True)
file_path=pd.ExcelWriter('C:/Users/Dell/Desktop/test/并购公告/2019-2021并购公告.xlsx') #指定生成的Excel表格名称
pf.fillna('', inplace=True) #替换空单元格
pf.to_excel(file_path, encoding='utf-8', index=False) #输出
file_path.save()
if __name__=='__main__':
export_excel() #将分析完成的列表导出为excel表格