Halcom 发表于 2020-9-13 23:05:06

python抓取大乐透历史数据

python抓取大乐透历史数据代码:from bs4 importBeautifulSoupas bs
import requests
import os

def get_url():
    data_1 = []
    for i in range(0,110):
      url = 'http://www.lottery.gov.cn/historykj/history_'+ str(i) +'.jspx?_ltype=dlt'
      data= requests.get(url).text
      data= bs(data,'lxml')
      data = data.find('tbody').find_all('tr')
      for content in data:
            number = content.get_text().strip().replace('\r','').replace('\t','').replace('\n',' ')
            with open('data_recent','a') as f:
                f.write(number+'\n')
    f.close()
if __name__ == '__main__':
    get_url()

结果:
20088 02 07 23 26 35 01 12 3 10,000,000 1 8,000,000 105 136,300 40 109,040      297,982,352 868,351,367.23 2020-09-12
20087 01 04 20 23 29 04 08 2 10,000,000 1 8,000,000 55 272,660 18 218,128      285,933,804 840,146,318.60 2020-09-09
20086 08 11 15 20 28 04 10 6 10,000,000 2 8,000,000 95 133,505 38 106,804      273,366,854 801,056,869.71 2020-09-07
20085 03 04 11 15 28 02 03 19 5,878,445 4 4,702,756 392 20,000 112 16,000      295,847,488 817,700,325.61 2020-09-05
20084 02 10 20 24 31 06 12 6 10,000,000 1 8,000,000 70 196,210 24 156,968      281,668,774 917,779,485.86 2020-09-02
20083 01 02 17 32 34 04 09 5 10,000,000 1 8,000,000 56 298,130 11 238,504      271,235,594 923,726,886.74 2020-08-31
20082 02 11 12 21 34 04 08 7 8,556,891 3 6,845,512 185 63,356 59 50,684      291,838,192 913,232,816.11 2020-08-29
20081 01 13 15 32 35 08 10 2 10,000,000 0 0.00 44 319,505 15 255,604      266,594,465 941,509,338.17 2020-08-26
20080 03 06 22 24 25 09 10 8 7,392,120 5 5,913,696 129 80,860 34 64,688      263,844,694 898,072,957.75 2020-08-24
20079 04 16 24 29 35 02 12 5 10,000,000 1 8,000,000 78 187,470 29 149,976      292,614,622 941,997,905.73 2020-08-22
20078 14 18 20 28 34 10 11 2 10,000,000 0 0.00 63 235,153 15 188,122      269,949,871 932,733,357.90 2020-08-19
20077 17 23 28 29 32 01 03 0 0.00 0 0.00 65 213,251 22 170,600      270,568,843 890,203,888.20 2020-08-17
20076 01 08 18 28 30 10 12 7 9,172,500 1 7,338,000 184 61,724 60 49,379      294,292,139 827,752,078.21 2020-08-15
20075 02 09 10 21 35 01 07 4 10,000,000 0 0.00 59 217,584 22 174,067      271,697,395 848,526,594.54 2020-08-12
20074 03 09 10 12 21 04 11 8 8,240,826 1 6,592,660 166 66,605 28 53,284      270,785,594 829,434,509.37 2020-08-10
20073 04 10 12 23 27 08 09 7 9,742,502 1 7,794,001 129 91,542 61 73,233      298,601,828 857,463,717.87 2020-08-08
参考:
【1】https://www.lottery.gov.cn/historykj/history_0.jspx?_ltype=dlt
【2】python爬彩票大乐透历史数据+预测测试...




页: [1]
查看完整版本: python抓取大乐透历史数据