python3爬虫--抓取天气信息
来源:互联网 发布:12306网络订餐配送工 编辑:程序博客网 时间:2024/05/01 05:16
抓取中国天气网上的数据并打出
Version:Python3.5 Os:win10
import urllib.request
import re
import time
if __name__=='__main__':
url = 'http://www.weather.com.cn/weather/101010100.shtml'
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req=urllib.request.Request(url=url,headers=header)
webPage=urllib.request.urlopen(req)
data = webPage.read()
data = data.decode('utf-8')
date=time.strftime("%Y-%m-%d %H:%M %p", time.localtime())
regzone='<a href="http://bj.weather.com.cn" target="_blank">(.*?)</a>'
regdis='<p class="wea" title="(.*?)">'
reg='<p class=.*?>\n<span>(.*?)</span>/\n<i>(.*?)</i>'
w=re.compile(reg).findall(data)
wz=re.compile(regzone).findall(data)
wdis=re.compile(regdis).findall(data)
print(date,wz[0],w[0],wdis[0])
顺便写个gui界面:
from tkinter import *
import urllib.request
import re
import time
url = 'http://www.weather.com.cn/weather/101010100.shtml'
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req=urllib.request.Request(url=url,headers=header)
webPage=urllib.request.urlopen(req)
data = webPage.read()
data = data.decode('utf-8')
date=time.strftime("%Y-%m-%d %H:%M %p", time.localtime())
regzone='<a href="http://bj.weather.com.cn" target="_blank">(.*?)</a>'
regdis='<p class="wea" title="(.*?)">'
reg='<p class=.*?>\n<span>(.*?)</span>/\n<i>(.*?)</i>'
w=re.compile(reg).findall(data)
wz=re.compile(regzone).findall(data)
wdis=re.compile(regdis).findall(data)
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.helloLabel = Label(self, text=date+' '+wz[0]+'\n'+wdis[0]+'\n'+'气温范围'+str(w[0]))
self.helloLabel.pack()
app = Application()
# 设置窗口标题:
app.master.title('实时温度')
# 主消息循环:
app.mainloop()
- python3爬虫--抓取天气信息
- python3爬虫--抓取网页信息
- Python爬虫学习,抓取网页上的天气信息
- 爬虫:抓取某年某月某日某地的天气信息
- python3获取天气信息
- python3.x爬虫实战:阿里巴巴网站定向信息抓取
- Python3.4 简单抓取爬虫
- Python3 爬虫--批量抓取图片
- python3 urllib爬虫抓取记录
- Python3爬虫小程序——爬取各类天气信息
- Python3爬虫小程序——爬取各类天气信息(2)
- Python3爬虫小程序——爬取各类天气信息(3)
- Python3爬虫小程序——爬取各类天气信息(4)
- 爬虫抓取火车票信息
- 爬虫Scrapy学习指南之抓取新浪天气
- python3的爬虫抓取猫眼电影的信息(requests+正则表达式)
- python练习--天气信息抓取(1)
- 树莓派使用Python3获取天气信息
- Python 下的数据结构实现
- 数据结构实验之栈二:一般算术表达式转换成后缀式
- display的inline、block、inline-block 的区别
- 在activity里获取adapter的控件
- 日期控件 及显示
- python3爬虫--抓取天气信息
- JVM加载class文件的机制
- Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition
- ORA-00205: error in identifying control file, check alert log for more info
- POJ2632Crashing Robots
- jQuery自定义滚动条样式插件mCustomScrollbar
- tensorflow在windows环境下的安装
- s3c2440时钟系统分析
- LNMP更改默认mysql数据存放到数据盘