-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-download-content.py
More file actions
41 lines (33 loc) · 891 Bytes
/
get-download-content.py
File metadata and controls
41 lines (33 loc) · 891 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import argparse
import requests
# Create an ArgumentParser object
parser = argparse.ArgumentParser(description='Web scraping tool.')
# Add command-line arguments
parser.add_argument(
'--url',
type=str,
required=True,
help='The URL to scrape data from.'
)
parser.add_argument(
'--output_file',
type=str,
default='scraped_data.txt',
help='Path to the output file (default: scraped_data.txt).'
)
parser.add_argument(
'--log',
action='store_true',
help='Enable logging of the scraping process (default: disabled).'
)
# Parse command-line arguments
args = parser.parse_args()
# Perform the web scraping
response = requests.get(args.url)
data = response.text
# Save the scraped data
with open(args.output_file, 'w') as file:
file.write(data)
if args.log:
print(f'URL scraped: {args.url}')
print(f'Data saved to: {args.output_file}')