python|python 爬虫抓取图片

【python|python 爬虫抓取图片】最好的方法是不看语法不看文档,用什么搜什么
抓取图片

import urllib.request import re def dowload_page(url): request = urllib.request.urlopen(url) data = https://www.it610.com/article/request.read() return data def get_html(url): request = urllib.request.urlopen(url) data = request.read() hmtl =data.decode('UTF-8') return hmtl def get_image(html): regx = r'http://[\S]*\.jpg' pattern = re.compile(regx) get_img = re.findall(pattern,repr(html)) print(get_img) print('aaa') num =1 for img in get_img: image = dowload_page(img) with open('%s.jpg'%num,'wb') as fp: fp.write(image) num += 1 print('正在下载第%s张图片'%num) returnhtml =get_html('http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%B7%E7%BE%B0&fr=ala&ala=1&alatpl=adress&pos=0&hs=2&xthttps=000000') get_image(html)```

    推荐阅读