import requests # txt文件,存储股票代码,一行一个代码,小写字母 f = open(r"G:pycharm_codestock.txt") symbols = [line.strip() for line in f.readlines()] f.close() def getQuote(sym): url = 'http://hq.sinajs.cn/list=' + sym res = requests.get(url).text # print(res) # 此处输出与浏览器页面获取的数据一致 quote = res[14:-3].replace('="', ',').split(',') # 删除、替换无关字符 print(quote) for symbol in symbols: # 遍历股票列表,逐条输出股票数据 getQuote(symbol)
参考
Python 抓取新浪财经股票数据 - https://blog.csdn.net/withchris/article/details/62420085