-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
31 lines (21 loc) · 827 Bytes
/
parser.py
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 requests
from urllib import request
from bs4 import BeautifulSoup
def parse_links(base_link, max_prods):
pic_links = list()
LIMIT_PARAM = "?limit="
page_html = request.urlopen(base_link + LIMIT_PARAM + str(max_prods))
soup = BeautifulSoup(page_html, 'lxml')
for pic in soup.find_all('a', {'class': 'product-image'}):
pic_links.append(pic.find('img').get('src'))
return pic_links
def link_to_pick(links, save_dir):
for i in range(len(links)):
with open(save_dir + str(i) + '.jpg', 'wb') as handle:
response = requests.get(links[i], stream=True)
if not response.ok:
print(response)
for block in response.iter_content(1024):
if not block:
break
handle.write(block)