notice_content用于回傳股票資訊地雷內容。目前我在用的版本會回傳錯誤“list index out of range”。通過調整改函式內容,對此問題做了修正,特此記錄。處理步驟如下:
1、找到python安裝目錄下:\Lib\site-packages\tushare\stock檔案夾
2、找到notice_content所在檔案newsevent.py
3、原函式內容為:
try:
html = lxml.html.parse(url)
res = html.xpath('//div[@id=\"content\"]/pre/text()')
return res.strip()
except Exception as er:
print(str(er))
修改為:
try:
html = lxml.html.parse(url)
cont = html.xpath('//div[@id=\"content\"]/p/text()')
res=''
for loop_num in range(0,len(cont)):
res=res+cont[loop_num].strip()
return res
except Exception as er:
print(str(er))
4、修改后,保存。退出python,重新進入import tushare即可生效。修改后正常回傳公告內容字串。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/133058.html
上一篇:python 中截取的json字串 怎么提取 [] json資料
下一篇:谷歌瀏覽器的這種彈窗是什么型別的
