mport urllib.request

import re
 
codeUrl = 'https://hq.gucheng.com/gpdmylb.html'
 
#获取股票代码
def codeTolist():
    codeList = []
    html = urllib.request.urlopen(codeUrl).read()
    html = html.decode('utf-8')
    = '<a href="https://hq.gucheng.com/(SZ|SH)(.*?)/">'
    = re.compile(s)
    data = p.findall(html)
    for code in data:
        codeList.append(code[1])
    return codeList
 
allCodeList = codeTolist()
 
#下载股票数据
def allDown():
    = len(allCodeList)
    for code in allCodeList:
        print(f'正在获取{code}股票数据')
        if code[0=='6':
            Url = 'http://quotes.money.163.com/service/chddata.html?code=0'+code+\
                '&start=19981218&end=20191213&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP'
        else:
            Url = 'http://quotes.money.163.com/service/chddata.html?code=1'+code+\
                '&start=19981218&end=20191213&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP'
        urllib.request.urlretrieve(Url,'d:\\gupiao\\'+code+'.csv')
        = -1
        if == 0:
            print('所有股票下载完毕!')
allDown()

相关文章:

  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-12-23
  • 2021-05-08
猜你喜欢
  • 2021-12-27
  • 2021-12-26
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案