webimg 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- webimg-0.1.0/LICENSE +21 -0
- webimg-0.1.0/PKG-INFO +63 -0
- webimg-0.1.0/README.md +45 -0
- webimg-0.1.0/pyproject.toml +29 -0
- webimg-0.1.0/setup.cfg +4 -0
- webimg-0.1.0/webimg/__init__.py +4 -0
- webimg-0.1.0/webimg/core.py +88 -0
- webimg-0.1.0/webimg.egg-info/PKG-INFO +63 -0
- webimg-0.1.0/webimg.egg-info/SOURCES.txt +10 -0
- webimg-0.1.0/webimg.egg-info/dependency_links.txt +1 -0
- webimg-0.1.0/webimg.egg-info/requires.txt +2 -0
- webimg-0.1.0/webimg.egg-info/top_level.txt +1 -0
webimg-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Himal Bhattarai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
webimg-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webimg
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Download all images from a webpage in one function call
|
|
5
|
+
Author: Himal Bhattarai
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: images,download,scraping,webpage,web scraping
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: beautifulsoup4
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# webimg
|
|
20
|
+
|
|
21
|
+
Download every image from a webpage in one function call.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install webimg
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
(This also installs its two dependencies, `requests` and `beautifulsoup4`.)
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import webimg
|
|
35
|
+
|
|
36
|
+
webimg.download("https://example.com")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
That's it — it scans the page, finds every image, and saves them into an
|
|
40
|
+
`images/` folder in your current directory.
|
|
41
|
+
|
|
42
|
+
### Optional: choose the output folder
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import webimg
|
|
46
|
+
|
|
47
|
+
webimg.download("https://example.com", output_dir="my_photos")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Optional: get the list of saved file paths
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import webimg
|
|
54
|
+
|
|
55
|
+
saved_files = webimg.download("https://example.com")
|
|
56
|
+
print(saved_files)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- Only works on static HTML pages. JS-heavy sites that load images dynamically
|
|
62
|
+
won't be fully captured.
|
|
63
|
+
- Please make sure you have the right to download and use the images.
|
webimg-0.1.0/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# webimg
|
|
2
|
+
|
|
3
|
+
Download every image from a webpage in one function call.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install webimg
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
(This also installs its two dependencies, `requests` and `beautifulsoup4`.)
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import webimg
|
|
17
|
+
|
|
18
|
+
webimg.download("https://example.com")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That's it — it scans the page, finds every image, and saves them into an
|
|
22
|
+
`images/` folder in your current directory.
|
|
23
|
+
|
|
24
|
+
### Optional: choose the output folder
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import webimg
|
|
28
|
+
|
|
29
|
+
webimg.download("https://example.com", output_dir="my_photos")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Optional: get the list of saved file paths
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import webimg
|
|
36
|
+
|
|
37
|
+
saved_files = webimg.download("https://example.com")
|
|
38
|
+
print(saved_files)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Notes
|
|
42
|
+
|
|
43
|
+
- Only works on static HTML pages. JS-heavy sites that load images dynamically
|
|
44
|
+
won't be fully captured.
|
|
45
|
+
- Please make sure you have the right to download and use the images.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "webimg"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Download all images from a webpage in one function call"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Himal Bhattarai" }
|
|
15
|
+
]
|
|
16
|
+
keywords = ["images", "download", "scraping", "webpage", "web scraping"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP :: Indexing/Search",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"requests",
|
|
25
|
+
"beautifulsoup4"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools]
|
|
29
|
+
packages = ["webimg"]
|
webimg-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
3
|
+
from bs4 import BeautifulSoup
|
|
4
|
+
from urllib.parse import urljoin, urlparse
|
|
5
|
+
|
|
6
|
+
HEADERS = {
|
|
7
|
+
"User-Agent": (
|
|
8
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
9
|
+
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
10
|
+
"Chrome/120.0 Safari/537.36"
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _get_image_urls(page_url):
|
|
16
|
+
resp = requests.get(page_url, headers=HEADERS, timeout=15)
|
|
17
|
+
resp.raise_for_status()
|
|
18
|
+
soup = BeautifulSoup(resp.text, "html.parser")
|
|
19
|
+
|
|
20
|
+
urls = set()
|
|
21
|
+
for img in soup.find_all("img"):
|
|
22
|
+
for attr in ("src", "data-src"):
|
|
23
|
+
val = img.get(attr)
|
|
24
|
+
if val:
|
|
25
|
+
urls.add(urljoin(page_url, val))
|
|
26
|
+
srcset = img.get("srcset")
|
|
27
|
+
if srcset:
|
|
28
|
+
for part in srcset.split(","):
|
|
29
|
+
candidate = part.strip().split(" ")[0]
|
|
30
|
+
if candidate:
|
|
31
|
+
urls.add(urljoin(page_url, candidate))
|
|
32
|
+
return list(urls)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _safe_filename(url, index):
|
|
36
|
+
name = os.path.basename(urlparse(url).path)
|
|
37
|
+
if not name or "." not in name:
|
|
38
|
+
name = f"image_{index}.jpg"
|
|
39
|
+
return name
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def download(url, output_dir="images"):
|
|
43
|
+
"""
|
|
44
|
+
Download every image found on the given webpage URL.
|
|
45
|
+
|
|
46
|
+
Usage:
|
|
47
|
+
import webimg
|
|
48
|
+
webimg.download("https://example.com")
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
url (str): The webpage URL to scan for images.
|
|
52
|
+
output_dir (str): Folder to save images into (default "images").
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
list[str]: Paths of the successfully saved image files.
|
|
56
|
+
"""
|
|
57
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
58
|
+
image_urls = _get_image_urls(url)
|
|
59
|
+
|
|
60
|
+
if not image_urls:
|
|
61
|
+
print("No images found on this page.")
|
|
62
|
+
return []
|
|
63
|
+
|
|
64
|
+
saved = []
|
|
65
|
+
print(f"Found {len(image_urls)} image(s). Downloading to '{output_dir}'...")
|
|
66
|
+
|
|
67
|
+
for i, img_url in enumerate(image_urls, start=1):
|
|
68
|
+
filename = _safe_filename(img_url, i)
|
|
69
|
+
filepath = os.path.join(output_dir, filename)
|
|
70
|
+
|
|
71
|
+
base, ext = os.path.splitext(filepath)
|
|
72
|
+
counter = 1
|
|
73
|
+
while os.path.exists(filepath):
|
|
74
|
+
filepath = f"{base}_{counter}{ext}"
|
|
75
|
+
counter += 1
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
img_resp = requests.get(img_url, headers=HEADERS, timeout=15)
|
|
79
|
+
img_resp.raise_for_status()
|
|
80
|
+
with open(filepath, "wb") as f:
|
|
81
|
+
f.write(img_resp.content)
|
|
82
|
+
saved.append(filepath)
|
|
83
|
+
print(f" Saved: {filepath}")
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(f" Failed ({img_url}): {e}")
|
|
86
|
+
|
|
87
|
+
print("Done.")
|
|
88
|
+
return saved
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webimg
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Download all images from a webpage in one function call
|
|
5
|
+
Author: Himal Bhattarai
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: images,download,scraping,webpage,web scraping
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: beautifulsoup4
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# webimg
|
|
20
|
+
|
|
21
|
+
Download every image from a webpage in one function call.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install webimg
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
(This also installs its two dependencies, `requests` and `beautifulsoup4`.)
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import webimg
|
|
35
|
+
|
|
36
|
+
webimg.download("https://example.com")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
That's it — it scans the page, finds every image, and saves them into an
|
|
40
|
+
`images/` folder in your current directory.
|
|
41
|
+
|
|
42
|
+
### Optional: choose the output folder
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import webimg
|
|
46
|
+
|
|
47
|
+
webimg.download("https://example.com", output_dir="my_photos")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Optional: get the list of saved file paths
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import webimg
|
|
54
|
+
|
|
55
|
+
saved_files = webimg.download("https://example.com")
|
|
56
|
+
print(saved_files)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- Only works on static HTML pages. JS-heavy sites that load images dynamically
|
|
62
|
+
won't be fully captured.
|
|
63
|
+
- Please make sure you have the right to download and use the images.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
webimg
|