python爬虫双色球
时间: 2023-11-08 20:55:23 浏览: 186
python爬虫
Sure! 要编写一个Python爬虫来获取双色球开奖号码,你可以使用requests库发送HTTP请求,并使用BeautifulSoup库解析HTML页面。以下是一个简单的示例代码:
```python
import requests
from bs4 import BeautifulSoup
def get_double_color_ball():
url = 'http://www.cwl.gov.cn/kjxx/ssq/hmhz/index.shtml'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 获取开奖号码的节点
node = soup.find('td', class_='td_kjhm_font')
# 提取双色球号码
ball_numbers = node.get_text().strip().split(' ')
return ball_numbers
result = get_double_color_ball()
print(result)
```
阅读全文