Skip to content

Commit 96d103e

Browse files
Add files via upload
0 parents  commit 96d103e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

Scrappingdrop.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Scraping Drop Project By Shravan
2+
3+
# Importing Libraries
4+
import mechanicalsoup
5+
import os
6+
import wget
7+
8+
browser = mechanicalsoup.StatefulBrowser()
9+
url = "https://www.google.com/imghp?hl=en"
10+
11+
browser.open(url)
12+
# get HTML
13+
browser.get_current_page()
14+
15+
# target the search input
16+
browser.select_form()
17+
18+
# searching for a term
19+
search_term = input("Enter a search term: ")
20+
browser["q"] = search_term
21+
22+
# submitting the search
23+
response = browser.submit_selected()
24+
25+
# opening of URL
26+
new_url = browser.get_url()
27+
browser.open(new_url)
28+
print(new_url, "\n")
29+
30+
# get HTML code
31+
page = browser.get_current_page()
32+
all_images = page.find_all('img')
33+
34+
# target the source attributes of image
35+
image_source = []
36+
for image in all_images:
37+
image = image.get('src')
38+
image_source.append(image)
39+
40+
image_source[5:25]
41+
image_source = [image for image in image_source if image.startswith('https')]
42+
image_source[5:]
43+
44+
path = os.getcwd()
45+
# just adding s to the end of the path name
46+
path = os.path.join(path, search_term + "s")
47+
48+
typechoice = input("Enter the type of image you want to download (jpg or png): ")
49+
if typechoice == "jpg":
50+
imgtype = ".jpg"
51+
elif typechoice == "png":
52+
imgtype = ".png"
53+
else:
54+
print("Invalid type")
55+
56+
# creating the directory
57+
os.mkdir(path)
58+
print('Your Query images are stored here: ', path)
59+
60+
# Saving the images according to type of image
61+
counter = 0
62+
for image in image_source:
63+
save_as = os.path.join(path, search_term + str(counter) + imgtype)
64+
wget.download(image, save_as)
65+
counter += 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy