Python爬取双色球历史号码代码示例
以下是一个爬取双色球往期号码的Python代码示例:
import requests
from bs4 import BeautifulSoup
url = 'http://datachart.500.com/ssq/history/newinc/history.php?start=03001&end=21036'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find('table', attrs={'class': 't1'})
rows = table.find_all('tr')[2:]
for row in rows:
data = row.find_all('td')
issue = data[0].text.strip()
red_balls = [ball.text.strip() for ball in data[1:7]]
blue_ball = data[7].text.strip()
print(issue, red_balls, blue_ball)
该代码使用requests和BeautifulSoup库来爬取双色球历史数据页面,然后使用find和find_all方法来找到表格和表格行。然后,我们遍历表格行并使用find_all方法来获取每行的单元格数据。最后,我们提取每行的期号、红球和蓝球号码并打印出来。
原文地址: https://www.cveoy.top/t/topic/nQnf 著作权归作者所有。请勿转载和采集!