导航菜单
首页 >  硕士毕业论文修改数据  > 毕业论文修改数据能看出来吗

毕业论文修改数据能看出来吗

如何用python爬取天气预报,python爬虫爬取天气数据

litangwang1145: temp.append(i['od24']) # 添加当前时刻风力方向temp.append(i['od25']) # 添加当前时刻风级temp.append(i['od26']) # 添加当前时刻降水量temp.append(i['od27']) # 添加当前时刻相对湿度temp.append(i['od28']) # 添加当前时刻控制质量#print(temp)final_day.append(temp) count = count +1 # 下面爬取7天的数据ul = data.find('ul') # 找到所有的ul标签 li = ul.find_all('li') # 找到左右的li标签 i = 0 # 控制爬取的天数 for day in li: # 遍历找到的每一个li if i < 7 and i >0: temp = [] # 临时存放每天的数据 date = day.find('h1').string # 得到日期 date = date[0:date.index('日')]# 取出日期号 temp.append(date) inf = day.find_all('p') # 找出li下面的p标签,提取第一个p标签的值,即天气 temp.append(inf[0].string) tem_low = inf[1].find('i').string# 找到最低气温 if inf[1].find('span') is None:# 天气预报可能没有最高气温 tem_high = None else: tem_high = inf[1].find('span').string # 找到最高气温 temp.append(tem_low[:-1]) if tem_hig

如何用python爬取天气预报,python爬虫爬取天气数据

litangwang1145: import requestsfrom bs4 import BeautifulSoupimport csvimport jsondef getHTMLtext(url):"""请求获得网页内容""" try:r = requests.get(url, timeout = 30)r.raise_for_status()r.encoding = r.apparent_encodingprint("成功访问")return r.textexcept:print("访问错误")return" " def get_content(html): """处理得到有用信息保存数据文件""" final = [] # 初始化一个列表保存数据('div', {'id': '7d'} )bs = BeautifulSoup(html, "html.parser") # 创建BeautifulSoup对象 body = bs.body data = body.find('div',{'id':'7d'})# 找到div标签且id = 7d # 下面爬取当天的数据 data2 = body.find_all('div',{'class':'left-div'}) text = data2[2].find('script').stringtext = text[text.index('=')+1 :-2]# 移除改var data=将其变为json数据 jd = json.loads(text) dayone = jd['od']['od2'] # 找到当天的数据 final_day = []# 存放当天的数据 count = 0 for i in dayone: temp = [] if count

相关推荐: