import urllib
import urllib.request
import re
def getHtml(url):
page=urllib.request.urlopen(url)
html=page.read()
return html
def getImg(html):
html=html.decode('utf-8')
reg=r'src="(.+?\.jpg)"'
imgre=re.compile(reg)
imglist=re.findall(imgre,html)
return imglist
html=getHtml("http://creativedreams.me/#modal-genius-hunt")
print(getImg(html))
因为python3中findall数据类型用bytes类型,因此应在正则表达式成使用类型转换。