Python实现一个简易的网页抓取程序

来源:互联网 发布:网络yy骗小钱 编辑:程序博客网 时间:2024/05/20 17:40
#coding=utf-8import urllibimport redef getHtml(url):    page = urllib.urlopen(url)    html = page.read()    return htmldef getImg(html):    reg = r'src="(.+?\.jpg)" pic_ext'    imgre = re.compile(reg)    imglist = re.findall(imgre,html)    x = 0    for imgurl in imglist:        urllib.urlretrieve(imgurl,'%s.jpg' % x)        x+=1html = getHtml("http://tieba.baidu.com/p/2460150866")print getImg(html)

0 0