Skip to content

Commit 1027f09

Browse files
committed
img scraper added
1 parent 9701ab0 commit 1027f09

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Image-Scraper/scrape_images.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Scrape all HTML <img> tags from a provided URL.
2+
3+
from bs4 import BeautifulSoup
4+
import requests
5+
import sys
6+
7+
if len(sys.argv) != 2:
8+
sys.exit("Usage: python scrape_images.py {url}")
9+
10+
response = requests.get(
11+
sys.argv[1],
12+
headers={
13+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
14+
}
15+
)
16+
17+
html_data = BeautifulSoup(response.text, 'html.parser')
18+
images = html_data.find_all('img', src=True)
19+
20+
for image in images:
21+
print(image)

0 commit comments

Comments
 (0)