现在的位置: 首页 > 综合 > 正文

爬行CSDN首页Image(Just Another Python Dome)

2018年03月22日 ⁄ 综合 ⁄ 共 366字 ⁄ 字号 评论关闭
#!/usr/bin/env python
#_*_coding:gb2312_*_
import re
import urllib
def getHtml(url):
    page=urllib.urlopen(url)
    html=page.read()
    return  html
def getImg(html):
    reg=r'src=\"(.*\.jpg)'
    image=re.compile(reg)
    imglist=re.findall(image,html)
    x=0
    for imgurl in imglist:
        urllib.urlretrieve(imgurl,'%s.jpg'%x)
        print imgurl
        x=x+1
html=getHtml('http://www.csdn.net')
getImg(html)

抱歉!评论已关闭.