一次获取大量股票

import requests
# txt文件,存储股票代码,一行一个代码,小写字母
f = open(r"G:\pycharm_code\stock.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

posted @ 2020-04-21 21:30  程式交易  阅读(253)  评论(0编辑  收藏  举报