资源简介
利用Python爬虫抓取必应每日壁纸,每四小时运行一次,在D盘下生成BingBG文件保存图片,在程序当前目录下生成log文件
代码片段和文件信息
import urllib2
import re
import os
import time
import thread
import logging
class BingBG:
def __init__(self):
mTime = time.time()
mOldTime = time.localtime(mTime)
self.strOldTime = str(mOldTime.tm_year) + str(mOldTime.tm_mon) + str(mOldTime.tm_mday)
self.strNewTime = str(““)
self. myUrl = “http://cn.bing.com“
self.user_agent = ‘Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)‘
self.headers = {‘User-Agent‘: self.user_agent}
self.picDir = r“D:\BingBG“
logging.info(“init app“)
def DownLoad(self):
req = urllib2.Request(self.myUrl headers=self.headers)
logging.info(“opening cn.bing.com“)
try:
res = urllib2.urlopen(req)
page = res.read()
items = re.findall(r“g_img={url: \“.*\.jpg\““ page)
if items:
mTime = time.time()
mLocalTime = time.localtime(mTime)
strLocalTime = str(mLocalTime.tm_year) + str(mLocalTime.tm_mon) + str(mLocalTime.tm_mday)
picUrl = self.myUrl + items[0][13:-1]
img_name = self.picDir + “\\“ + strLocalTime + “.jpg“
img_data = urllib2.urlopen(picUrl).read()
f = open(img_name ‘wb‘)
f.write(img_data)
f.close()
logging.info(“download success“)
else:
logging.info(“item not found“)
except:
- 上一篇:百度人脸识别-人脸对比
- 下一篇:自动发布mxd服务
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 一个多线程智能爬虫,爬取网站小说
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- 顶点小说单本书爬虫.py
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论