import re
import urllib.request
defgetHtml(url):
page = urllib.request.urlopen(url)
html = page.read()
return html
defgetImg(html):
reg = r'<a href="([.*\S]*\.html)" title='
imgre = re.compile(reg);
imglist = re.findall(imgre, html)
return imglist
url = "https://jingyan.baidu.com/user/npublic/?uid=d1b612bceb0dc22ba8ffe137&pn="for i in range(0,89*7,7):
i = str(i)
a = url+i
html = getHtml(a)
html = html.decode('UTF-8')
for i in getImg(html):
print("https://jingyan.baidu.com"+i)
爬取标题:
import re
import urllib.request
defgetHtml(url):
page = urllib.request.urlopen(url)
html = page.read()
return html
defgetImg(html):
reg = r'<a href="([.*\S]*\.html)" title='
reg = r'title="([.*\S]*\?)" target='
imgre = re.compile(reg);
imglist = re.findall(imgre, html)
return imglist
url = "https://jingyan.baidu.com/user/npublic/?uid=d1b612bceb0dc22ba8ffe137&pn="for i in range(0,89*7,7):
i = str(i)
a = url+i
html = getHtml(a)
html = html.decode('UTF-8')
for i in getImg(html):
print(i)