#!/usr/local/bin/python3.7
import urllib.request as urlre
import re
def open_url(url):
req = urlre.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36')
page = urlre.urlopen(req)
html = page.read().decode('utf-8')
print(type(html))
return html
def get_img(html):
p = r'src="(.+?\.jpg)" pic_ex'
imgsa = re.compile(p)
imglist = re.findall(imgsa,html)
return imglist
for each in imglist:
print(each)
x = 0
for each in imglist:
urlre.urlretrieve(each,':\\%s.jpg' % x)
x += 1
if __name__ == "__main__":
url ='http://tieba.baidu.com/p/2460150866'
get_img(open_url)
return _compile(pattern, flags).findall(string)
TypeError: expected string or bytes-like object