python爬虫入门实战---------一周天气预报爬取_Python爬虫实例扒取2345天气预报

寒假里学习了一下Python爬虫,使用最简单的方法扒取需要的天气数据,对,没听错,最简单的方法。甚至没有一个函数封装。。

网址:http://tianqi.2345.com/wea_history/53892.htm

火狐中右键查看网页源代码,没有发现天气数据,因此推断网页采用的json格式数据。

右击->查看元素->网络->JS,找到了位置

20180304141554150.png

用Python爬虫下载为json格式数据存储下来,代码如下:

#-*- coding:utf-8 -*-

import urllib2

import json

months = [1,2,3,4,5,6,7,8,9,10,11,12]

years = [2011,2012,2013,2014,2015,2016]

city = [53892] #邯郸代码53892

for y in years:

for m in months:

for c in city:

url = "http://tianqi.2345.com/t/wea_history/js/"+str(c)+"_"+str(y)+str(m)+".js?qq-pf-to=pcqq.c2c"

print url

html = urllib2.urlopen(url)

srcData = html.read()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值