pywebscrapr 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.
- pywebscrapr-0.1.0/LICENSE +7 -0
- pywebscrapr-0.1.0/PKG-INFO +24 -0
- pywebscrapr-0.1.0/README.md +76 -0
- pywebscrapr-0.1.0/pywebscrapr/__init__.py +122 -0
- pywebscrapr-0.1.0/pywebscrapr.egg-info/PKG-INFO +24 -0
- pywebscrapr-0.1.0/pywebscrapr.egg-info/SOURCES.txt +9 -0
- pywebscrapr-0.1.0/pywebscrapr.egg-info/dependency_links.txt +1 -0
- pywebscrapr-0.1.0/pywebscrapr.egg-info/requires.txt +2 -0
- pywebscrapr-0.1.0/pywebscrapr.egg-info/top_level.txt +1 -0
- pywebscrapr-0.1.0/setup.cfg +4 -0
- pywebscrapr-0.1.0/setup.py +30 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
MIT License (Modified)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to make derivative works based on the Software, provided that any substantial changes to the Software are clearly distinguished from the original work and are distributed under a different name.
|
|
4
|
+
|
|
5
|
+
The original copyright notice and disclaimer must be retained in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pywebscrapr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An open-source Python library for web scraping tasks.
|
|
5
|
+
Home-page: https://github.com/infinitode/pywebscrapr
|
|
6
|
+
Author: Infinitode Pty Ltd
|
|
7
|
+
Author-email: infinitode.ltd@gmail.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.6
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: beautifulsoup4
|
|
23
|
+
|
|
24
|
+
An open-source Python library for web scraping tasks. Includes support for both image scraping and text scraping.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# PyWebScrapr
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
An open-source Python library for web scraping tasks. Includes support for both text and image scraping.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
You can install PyWebScrapr using pip:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install pywebscrapr
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Supported Python Versions
|
|
19
|
+
|
|
20
|
+
PyWebScrapr supports the following Python versions:
|
|
21
|
+
|
|
22
|
+
- Python 3.6
|
|
23
|
+
- Python 3.7
|
|
24
|
+
- Python 3.8
|
|
25
|
+
- Python 3.9
|
|
26
|
+
- Python 3.10
|
|
27
|
+
- Python 3.11/Later (Preferred)
|
|
28
|
+
|
|
29
|
+
Please ensure that you have one of these Python versions installed before using PyWebScrapr. PyWebScrapr may not work as expected on lower versions of Python than the supported.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Text Scraping**: Extract textual content from specified URLs.
|
|
34
|
+
- **Image Scraping**: Download images from specified URLs.
|
|
35
|
+
|
|
36
|
+
<sub>*for a full list check out the PyWebScrapr Documentation.</sub>
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Text Scraping
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from pywebscrapr import scrape_text
|
|
44
|
+
|
|
45
|
+
# Specify links in a file or list
|
|
46
|
+
links_file = 'links.txt'
|
|
47
|
+
links_array = ['https://example.com/page1', 'https://example.com/page2']
|
|
48
|
+
|
|
49
|
+
# Scrape text and save to the 'output.txt' file
|
|
50
|
+
scrape_text(links_file=links_file, links_array=links_array, output_file='output.txt')
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Image Scraping
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from pywebscrapr import scrape_images
|
|
57
|
+
|
|
58
|
+
# Specify links in a file or list
|
|
59
|
+
links_file = 'image_links.txt'
|
|
60
|
+
links_array = ['https://example.com/image1.jpg', 'https://example.com/image2.png']
|
|
61
|
+
|
|
62
|
+
# Scrape images and save to the 'images' folder
|
|
63
|
+
scrape_images(links_file=links_file, links_array=links_array, save_folder='images')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
Contributions are welcome! If you encounter any issues, have suggestions, or want to contribute to PyWebScrapr, please open an issue or submit a pull request on [GitHub](https://github.com/infinitode/pywebscrapr).
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
PyWebScrapr is released under the terms of the **MIT License (Modified)**. Please see the [LICENSE](https://github.com/infinitode/pywebscrapr/blob/main/LICENSE) file for the full text.
|
|
73
|
+
|
|
74
|
+
**Modified License Clause**
|
|
75
|
+
|
|
76
|
+
The modified license clause grants users the permission to make derivative works based on the PyWebScrapr software. However, it requires any substantial changes to the software to be clearly distinguished from the original work and distributed under a different name.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import csv
|
|
3
|
+
import requests
|
|
4
|
+
from bs4 import BeautifulSoup
|
|
5
|
+
from urllib.parse import urlparse, urljoin
|
|
6
|
+
|
|
7
|
+
def _get_absolute_url(base_url, relative_url):
|
|
8
|
+
"""Helper function to get absolute URLs."""
|
|
9
|
+
return urljoin(base_url, relative_url)
|
|
10
|
+
|
|
11
|
+
def _download_image(url, save_path):
|
|
12
|
+
"""Helper function to download an image."""
|
|
13
|
+
response = requests.get(url)
|
|
14
|
+
with open(save_path, 'wb') as file:
|
|
15
|
+
file.write(response.content)
|
|
16
|
+
|
|
17
|
+
def scrape_images(links_file=None, links_array=None, save_folder='images'):
|
|
18
|
+
"""
|
|
19
|
+
Scrape image content from the given links and save to specified output folder.
|
|
20
|
+
|
|
21
|
+
Parameters:
|
|
22
|
+
- links_file (str): Path to a file containing links, with each link on a new line.
|
|
23
|
+
- links_array (list): List of links to scrape text from.
|
|
24
|
+
- output_folder (str): Folder to save the scraped images.
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
```python
|
|
28
|
+
from pywebscrapr import scrape_images
|
|
29
|
+
|
|
30
|
+
# Using links from a file and saving images to output_images folder.
|
|
31
|
+
scrape_text(links_file='links.txt', output_folder='output_images')
|
|
32
|
+
```
|
|
33
|
+
"""
|
|
34
|
+
if not os.path.exists(save_folder):
|
|
35
|
+
os.makedirs(save_folder)
|
|
36
|
+
|
|
37
|
+
links = []
|
|
38
|
+
if links_file:
|
|
39
|
+
with open(links_file, 'r') as file:
|
|
40
|
+
links = file.read().splitlines()
|
|
41
|
+
elif links_array:
|
|
42
|
+
links = links_array
|
|
43
|
+
else:
|
|
44
|
+
raise ValueError("Either 'links_file' or 'links_array' must be provided.")
|
|
45
|
+
|
|
46
|
+
for link in links:
|
|
47
|
+
response = requests.get(link)
|
|
48
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
49
|
+
|
|
50
|
+
for img_tag in soup.find_all('img'):
|
|
51
|
+
img_url = _get_absolute_url(link, img_tag.get('src'))
|
|
52
|
+
|
|
53
|
+
# Skip data URLs
|
|
54
|
+
if not img_url.startswith('data:'):
|
|
55
|
+
img_name = os.path.basename(urlparse(img_url).path)
|
|
56
|
+
save_path = os.path.join(save_folder, img_name)
|
|
57
|
+
_download_image(img_url, save_path)
|
|
58
|
+
|
|
59
|
+
def scrape_text(links_file=None, links_array=None, output_file='output.txt', csv_output_file=None, remove_extra_whitespace=True):
|
|
60
|
+
"""
|
|
61
|
+
Scrape textual content from the given links and save to specified output file(s).
|
|
62
|
+
|
|
63
|
+
Parameters:
|
|
64
|
+
- links_file (str): Path to a file containing links, with each link on a new line.
|
|
65
|
+
- links_array (list): List of links to scrape text from.
|
|
66
|
+
- output_file (str): File to save the scraped text.
|
|
67
|
+
- csv_output_file (str): File to save the URL and text information in CSV format.
|
|
68
|
+
- remove_extra_whitespace (bool): If True, remove extra whitespace and empty lines from the output.
|
|
69
|
+
|
|
70
|
+
Example:
|
|
71
|
+
```python
|
|
72
|
+
from pywebscrapr import scrape_text
|
|
73
|
+
|
|
74
|
+
# Using links from a file and saving text to output.txt
|
|
75
|
+
scrape_text(links_file='links.txt', output_file='output.txt')
|
|
76
|
+
|
|
77
|
+
# Using links directly and saving text to output.txt and csv_output.csv with extra whitespace removal
|
|
78
|
+
links = ['https://example.com/page1', 'https://example.com/page2']
|
|
79
|
+
scrape_text(links_array=links, output_file='output.txt', csv_output_file='csv_output.csv', remove_extra_whitespace=True)
|
|
80
|
+
```
|
|
81
|
+
"""
|
|
82
|
+
links = []
|
|
83
|
+
if links_file:
|
|
84
|
+
with open(links_file, 'r') as file:
|
|
85
|
+
links = file.read().splitlines()
|
|
86
|
+
elif links_array:
|
|
87
|
+
links = links_array
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError("Either 'links_file' or 'links_array' must be provided.")
|
|
90
|
+
|
|
91
|
+
all_text = ""
|
|
92
|
+
csv_data = []
|
|
93
|
+
|
|
94
|
+
for link in links:
|
|
95
|
+
response = requests.get(link)
|
|
96
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
97
|
+
|
|
98
|
+
for element in soup.find_all(lambda tag: tag.name not in ['script', 'style']):
|
|
99
|
+
if remove_extra_whitespace:
|
|
100
|
+
text = element.get_text(strip=True) # Remove extra whitespace
|
|
101
|
+
if text: # Skip empty lines
|
|
102
|
+
all_text += text + "\n"
|
|
103
|
+
else:
|
|
104
|
+
text = element.get_text()
|
|
105
|
+
all_text += text + "\n"
|
|
106
|
+
if csv_output_file:
|
|
107
|
+
csv_data.append({'URL': link, 'Text': text})
|
|
108
|
+
|
|
109
|
+
# Save text to output file
|
|
110
|
+
with open(output_file, 'w', encoding='utf-8') as text_file:
|
|
111
|
+
if remove_extra_whitespace:
|
|
112
|
+
text_file.write(all_text.rstrip()) # Remove trailing whitespace
|
|
113
|
+
else:
|
|
114
|
+
text_file.write(all_text)
|
|
115
|
+
|
|
116
|
+
# Save CSV data to CSV file
|
|
117
|
+
if csv_output_file:
|
|
118
|
+
with open(csv_output_file, 'w', newline='', encoding='utf-8') as csv_file:
|
|
119
|
+
fieldnames = ['URL', 'Text']
|
|
120
|
+
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
|
121
|
+
writer.writeheader()
|
|
122
|
+
writer.writerows(csv_data)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pywebscrapr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An open-source Python library for web scraping tasks.
|
|
5
|
+
Home-page: https://github.com/infinitode/pywebscrapr
|
|
6
|
+
Author: Infinitode Pty Ltd
|
|
7
|
+
Author-email: infinitode.ltd@gmail.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Requires-Python: >=3.6
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: beautifulsoup4
|
|
23
|
+
|
|
24
|
+
An open-source Python library for web scraping tasks. Includes support for both image scraping and text scraping.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pywebscrapr
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='pywebscrapr',
|
|
5
|
+
version='0.1.0',
|
|
6
|
+
author='Infinitode Pty Ltd',
|
|
7
|
+
author_email='infinitode.ltd@gmail.com',
|
|
8
|
+
description='An open-source Python library for web scraping tasks.',
|
|
9
|
+
long_description='An open-source Python library for web scraping tasks. Includes support for both image scraping and text scraping.',
|
|
10
|
+
long_description_content_type='text/markdown',
|
|
11
|
+
url='https://github.com/infinitode/pywebscrapr',
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
install_requires=[
|
|
14
|
+
'requests',
|
|
15
|
+
'beautifulsoup4',
|
|
16
|
+
],
|
|
17
|
+
classifiers=[
|
|
18
|
+
'Development Status :: 3 - Alpha',
|
|
19
|
+
'Intended Audience :: Developers',
|
|
20
|
+
'License :: OSI Approved :: MIT License',
|
|
21
|
+
'Programming Language :: Python :: 3.6',
|
|
22
|
+
'Programming Language :: Python :: 3.7',
|
|
23
|
+
'Programming Language :: Python :: 3.8',
|
|
24
|
+
'Programming Language :: Python :: 3.9',
|
|
25
|
+
'Programming Language :: Python :: 3.10',
|
|
26
|
+
'Programming Language :: Python :: 3.11',
|
|
27
|
+
'Programming Language :: Python :: 3.12',
|
|
28
|
+
],
|
|
29
|
+
python_requires='>=3.6',
|
|
30
|
+
)
|