python爬取天气数据的header_[python爬虫]爬取天气网全国所有县市的天气数据
def get_data(url):
html = ask_url(url)
base_url = 'http://www.weather.com.cn'
province_name = []# 省份名字
# province_url = []# 省份的URL
city_name = []# 城市名称
weather = []# 天气现象
wind_direction = []# 风向
wind_power = []# 风力
max_temperature = []# 最高温
min_temperature = []# 最低温
data = []# 数据汇总
province_name_decode = html.xpath('//div[@class="lqcontentBoxheader"]//a[@target="_blank"]/text()')
for i in range(len(province_name_decode)):
# print(province_name_decode[i].encode('raw_unicode_escape').decode())
province_name.append(province_name_decode[i].encode('raw_unicode_escape').decode())
province_url = html.xpath('//div[@class="lqcontentBoxheader"]//a[@target="_blank"]/@href')# 省份的URL
# print(province_url)
for j in range(len(province_url)):
# for j in range(0, 1):
temp_url = base_url + province_url[j]
province_html = ask_url(temp_url)
# 城市名称
city_name_decode = province_html.xpath('//div[@class="hanml"]/div[1]//td[contains(@width, "83") and contains(@height, "23")]/a[1]/text()')
for n in range(len(city_name_decode)):
# print(city_name_decode[n].encode('raw_unicode_escape').decode())
city_name.append(city_name_decode[n].encode('raw_unicode_escape').decode())
# 天气现象
weather_decode = province_html.xpath('//div[@class="hanml"]/div[1]//div[@class="conMidtab3"]//td[@width="89"]/text()')
for n in range(len(weather_decode)):
# print(weather_decode[n].encode('raw_unicode_escape').decode())
weather.append(weather_decode[n].encode('raw_unicode_escape').decode())
# 风向和风力
wind_direction_decode = province_html.xpath('//div[@class="hanml"]/div[1]//div[@class="conMidtab3"]//td[@width="162"]/span[1]/text()')
for n in range(len(wind_direction_decode)):
# print(wind_direction_decode[n].encode('raw_unicode_escape').decode())
wind_direction.append(wind_direction_decode[n].encode('raw_unicode_escape').decode())
wind_power_decode = province_html.xpath('//div[@class="hanml"]/div[1]//div[@class="conMidtab3"]//td[@width="162"]/span[@class="conMidtabright"]/text()')
for n in range(len(wind_power_decode)):
# print(wind_power_decode[n].encode('raw_unicode_escape').decode())
wind_power.append(wind_power_decode[n].encode('raw_unicode_escape').decode())
# 最高温
max_temperature_decode = province_html.xpath('//div[@class="hanml"]/div[1]//div[@class="conMidtab3"]//td[@width="92"]/text()')
for n in range(len(max_temperature_decode)):
# print(max_temperature_decode[n])
max_temperature.append(max_temperature_decode[n])
# 最低温
min_temperature_decode = province_html.xpath('//div[@class="hanml"]/div[1]//div[@class="conMidtab3"]//td[@width="86"]/text()')
for n in range(len(min_temperature_decode)):
# print(min_temperature_decode[n])
min_temperature.append(min_temperature_decode[n])
data.append(city_name)
data.append(weather)
data.append(wind_direction)
data.append(wind_power)
data.append(max_temperature)
data.append(min_temperature)
return data
python爬取天气数据的header_[python爬虫]爬取天气网全国所有县市的天气数据相关推荐
- [python爬虫]爬取天气网全国所有县市的天气数据
[python爬虫]爬取天气网全国所有县市的天气数据 访问URL 解析数据 保存数据 所要用到的库 import requests from lxml import etree import xlwt ...
- 【Python】大数据挖掘课程作业1——使用爬虫爬取B站评论、弹幕与UP主的投稿视频列表
[Python]大数据挖掘课程作业1--使用爬虫爬取B站评论.弹幕与UP主的投稿视频列表 数据挖掘部分的基本目标是:对于指定的UP主,能够获取其投稿视频列表:对于指定的视频,能够获取其视频标签.评论( ...
- python爬取微博评论点赞数_python 爬虫 爬微博 分析 数据
python 爬虫 爬微博分析 数据 最近刚看完爱情公寓5,里面的大力也太好看了吧... 打开成果的微博,小作文一样的微博看着也太爽了吧... 来 用python分析分析 狗哥这几年微博的干了些啥. ...
- python爬虫爬取京东商品评价_网络爬虫-爬取京东商品评价数据
前段时间做商品评价的语义分析,需要大量的电商数据,于是乎就自己动手爬取京东的数据.第一次接触爬虫是使用selenium爬取CNKI的摘要,基于惯性思维的我仍然想用selenium+Firefox的方法 ...
- python爬去百度百科词条_python简单爬虫爬取百度百科python词条网页
目标分析: 目标:百度百科python词条相关词条网页 - 标题和简介 入口页:https://baike.baidu.com/item/Python/407313 URL格式: - 词条页面URL: ...
- python多线程爬虫 爬取多个网页_python多线程爬虫爬取顶点小说内容(BeautifulSoup+urllib)...
思路 之前写过python爬取起点中文网小说,多线程则是先把爬取的章节链接存到一个列表里,然后写一个函数get_text每次调用这个函数就传一个章节链接,那么就需要调用n次该函数来获取n章的内容,所以 ...
- 【Python随笔】一天搞定,爬虫爬取w3schools的sql语句案例集
在很久以前的Easy Python系列中,介绍了通过爬虫手段爬取豆瓣电影信息的一种技术套路.今天故技重施,为了迎合先前做SQL语句分析的需要,决定爬取w3schools网站上面所有SQL案例,用作测试 ...
- 爬一个人的所有微博 python_pyhton爬虫爬取微博某个用户所有微博配图
前几天写了个java爬虫爬花瓣网,但是事后总感觉不够舒服,终于在今天下午写了个python爬虫(爬微博图片滴),写完之后就感觉舒服了,果然爬虫就应该用python来写,哈哈(这里开个玩笑,非引战言论) ...
- beautifulsoup爬取网页中的表格_Python爬虫爬取BT之家找电影资源
一.写在前面 最近看新闻说圣城家园(SCG)倒了,之前BT天堂倒了,暴风影音也不行了,可以说看个电影越来越费力,国内大厂如企鹅和爱奇艺最近也出现一些幺蛾子,虽然目前版权意识虽然越来越强,但是很多资源在 ...
最新文章
- ubuntu12.0.4不能正常关机和重启的解决方法
- PHP: chr和pack、unpack那些事
- FPGA之道(38)VHDL与Verilog的比较
- Swift使用通知Notification
- 哈理工大学计算机专业宿舍,计算机学院举办“灯塔工程”之寝室文化节
- jenkins搭建_自动化测试系列之jenkins配置搭建环境
- 没事随便写写——matlab图像与矩阵的转换与存储为txt文件
- PCB布局,布线技巧总结
- java gui 单选_java GUI编程(swing)之三swing单选框复选框组件
- Linq GroupJoin 使用
- 初学者python笔记(迭代器、生成器、三元表达式、列表解析、send()与yield())
- OpenSSH学习笔记(安装配置openssh-4.6p1)[zz]
- Python基础-Pygame游戏框架之飞机大战
- server2012文件服务器的开始按钮,Windows Server 2012实用技巧集锦
- 四元数和旋转_使用OpenCV的四元数
- android-sdk环境变量配置
- 14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
- android u盘检测工具,android 检测是否插入U盘方法之一
- 20款最好的jQuery文件上传插件
- 中概股的「劫难」、美团的「回头草」以及你价值「2000 元」的脸|极客一周...