Python 天气预报写入Excel中

本文介绍如何利用Python编程从天气API获取实时天气信息,并将这些数据写入Excel表格,以便进行数据分析和存储。
摘要由CSDN通过智能技术生成

程序参考:SPOTO世博在线教育

import requests
from bs4 import BeautifulSoup
import xlwt
import time
headers = {
   
     'User-Agent':'Mozilla/5.0'}
url = "http://www.weather.com.cn/weather/101270101.shtml"
weather_str = requests.get(url,headers = headers)
weather_str_content = weather_str.content
#print(weather_str_content)
soup = BeautifulSoup(weather_str_content,'html.parser')
soup_ul = soup.find('ul',"t clearfix")
#print(soup_ul)
#提取数据
soup_li_list = soup_ul.find_all("li")
weather_list = []
for i in range(len(soup_li_list)):
    #天气
    weather_data = soup_li_list[i].find("h1").get_text()
    #print(weather_data)
    #天气
    weather_wea = soup_li_list
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值