首页 > 其他 > 详细

Bing爬虫源码

时间:2016-07-13 01:33:16      阅读:257      评论:0      收藏:0      [点我收藏+]

BingBong架构采用MFC处理UI搭建、配置处理,Python实现爬虫模块的架构。调用时将对应的参数传入爬虫模块,随后爬虫开始下载。

 

Python代码相对简单,耗时的反而是找各种第三库的资料啊~

#!C:\Python27\python
# -*- coding: utf-8 -*-
import string,urllib2,re,time,sys
import win32api, win32con, win32gui
import Image

#主函数
def BingBong(path,cho):
    response = urllib2.urlopen(http://cn.bing.com/)
    html = response.read()

    pattern = re.compile( rhttp://s.cn.bing.net + .*?\.jpg )
    match = pattern.search( html )

    if match:
        #print u‘图片搜索成功!‘
        #print match.group()
        conn = urllib2.urlopen( match.group() )
        Date = time.strftime(%Y-%m-%d,time.localtime(time.time()))
        jpgPath = path + Date + .jpg
        f = open( jpgPath,wb )
        f.write(conn.read())
        f.close()
        
        if cho:
            setWallPaper( jpgPath,sys.argv[3] )
        
        #print u‘图片已保存!‘
    else:
        print u图片搜索失败!
        
def setWallpaperFromBMP(imagepath):   
    k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
    win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2") #2拉伸适应桌面,0桌面居中
    win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath, 1+2)
    
    # convert jpg to bmp
def setWallPaper(imagePath,SavePath):
    bmpImage = Image.open(imagePath) 
    #newPath = imagePath.replace(‘.jpg‘, ‘.bmp‘) 
    bmpImage.save(SavePath, "BMP")
    setWallpaperFromBMP(SavePath)
        
#print u‘请输入保存图片的路径:‘
path = sys.argv[1]
cho = int(sys.argv[2])

BingBong(path,cho)

 

Bing爬虫源码

原文:http://www.cnblogs.com/Avalon2016/p/5665417.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!