-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13.py
More file actions
19 lines (19 loc) · 824 Bytes
/
Copy path13.py
File metadata and controls
19 lines (19 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from urllib.request import urlopen
from urllib.request import urlretrieve
from bs4 import BeautifulSoup
import datetime
import re
html=urlopen("http://www.pythonscraping.com")
bsObj=BeautifulSoup(html.read())
#imageLocations=bsObj.findAll("img")
#print(len(imageLocations))
#for imageLocation in imageLocations:
#print(imageLocation.attrs["src"])
#for imageLocation in imageLocations:
#urlretrieve(imageLocation.attrs["src"],"logo"+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+".jpg")
imageLocations= bsObj.findAll("",{"src":re.compile("(\.jpg|\.gif)$")})
print(len(imageLocations))
for imageLocation in imageLocations:
print(imageLocation.attrs["src"])
for imageLocation in imageLocations:
urlretrieve(imageLocation.attrs["src"],"logo"+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+".jpg")