python写的简单有效的爬虫代码

来源:互联网 发布:node webservice 编辑:程序博客网 时间:2024/05/27 20:45

python写的简单有效的爬虫代码

by 伍雪颖

import reimport urllib                                 def getHtml(url):        html = urllib.urlopen(url)        scode = html.read()        return scode                                 def getImage(source):        reg = r'src="(.*?\.jpg)"'        imgre = re.compile(reg)        images = re.findall(imgre,source)        x = 0        for i in images:                urllib.urlretrieve(i,'%s.jpg' % x)                x+=1                                 source = getHtml('http://tieba.baidu.com/p/3237470549')print getImage(source)


0 0
原创粉丝点击