python reptile's regular expression search and seize information

import urllib.request
import re
def openl(url):
         r=urllib.request.Request(url)
         r.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0')
         am=urllib.request.urlopen(r)
         h=am.read().decode('utf-8')
         return h
def geti(h):
    p=r'<img alt="张哲瀚" id="mbpho-img" class="js-favorite-blogimg" src="(.*?\.jpeg)'
    i=re.findall(p,h)
    for e in i:
        f=e.split('/')[-1]
        urllib.request.urlretrieve(e,f,None)#下载图片


if __name__=='__main__':
    url='https://www.duitang.com/blog/?id=897699310'
    geti(openl(url))

在这里插入代码片
Published 130 original articles · won praise 16 · views 30000 +

Guess you like

Origin blog.csdn.net/feiqipengcheng/article/details/104639660