Python 爬虫笔记(三)

#用正则表达式爬取图片
#! /usr/bin/env python
#coding=utf-8

import urllib2
import  re 
from    bs4 import  BeautifulSoup

html=urllib2.urlopen("http://www.pythonscraping.com/pages/page3.html")
bsObj=BeautifulSoup(html)
images=bsObj.findAll("img", {"src":re.compile("\.\.\/img\/gifts/img.*\.jpg")})
for image in images:
            print(image["src"])

你可能感兴趣的:(python,爬虫,正则表达式,图片,utf-8)