-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
27 lines (19 loc) · 777 Bytes
/
Copy pathtest.py
File metadata and controls
27 lines (19 loc) · 777 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
from bs4 import BeautifulSoup
import requests
import os
def download_images(query, num_images):
base_url = 'https://www.google.co.in'
url = base_url + "/search?q=" + query + "&source=lnms&tbm=isch"
headers = {'User-Agent': "Mozilla/5.0"}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content,'html.parser')
images = soup.find_all(('img'))
for i,img in enumerate(images[:num_images+1]):
img_url = img['src']
if not img_url.startswith('http'):
img_url = base_url + img_url
response = requests.get(img_url)
if i !=0:
with open(f'C:\\image\\{query}_{i}.jpg','wb') as file:
file.write(response.content)
download_images('김채원 고화질',10)