python爬取分析超级大乐透历史开奖数据

摘自:https://blog.csdn.net/xucan_123/article/details/113943714

from bs4 import BeautifulSoup
import requests
import csv

lst = []
url = 'http://datachart.500.com/dlt/history/newinc/history.php?start=07001&end=23138'
r = requests.get(url)
r.encoding = 'utf-8'
text = r.text
soup = BeautifulSoup(text, "html.parser")
tbody = soup.find('tbody', id="tdata")
tr = tbody.find_all('tr')

# 动态确定网页上实际的行数
total_rows = len(tr)

for page in range(total_rows):
    td = tr[page].find_all('td')
    lst.append([td[0].text, td[1].text, td[2].text, td[3].text, td[4].text, td[5].text, td[6].text, td[7].text])

with open(r"C:\Users\abc\Desktop\Lottery_data.csv", 'w', newline='', encoding='gbk') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['期号', '号码1', '号码2', '号码3', '号码4', '号码5', '号码6', '号码7'])
    writer.writerows(lst)

作者:y0hv2y

出处:https://www.cnblogs.com/y0hv2y/p/17873689.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   yuhury  阅读(879)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
点击右上角即可分享
微信分享提示