-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcher抓图.py
More file actions
31 lines (21 loc) · 742 Bytes
/
Archer抓图.py
File metadata and controls
31 lines (21 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import urllib.request
import re
def open_url(url):
req=urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36')
page=urllib.request.urlopen(req)
html=page.read().decode('utf-8')
return html
def get_img(html):
p=r'<img class="BDE_Image" src="([^"]+\.jpg)"'
imglist=re.findall(p,html)
'''
for each in imglist:
print(each)
'''
for each in imglist:
filename=each.split("/")[-1]
urllib.request.urlretrieve(each,filename,None)
if __name__=='__main__':
url='https://tieba.baidu.com/p/4922639233'
get_img(open_url(url))