-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (32 loc) · 1.11 KB
/
main.py
File metadata and controls
36 lines (32 loc) · 1.11 KB
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
# main.py
from crawler import WebCrawler
import argparse
import sys
def parse_arguments():
"""
Parse command-line arguments for the web crawler.
:return: A tuple containing the root URL (str) and depth limit (int).
"""
parser = argparse.ArgumentParser(description='Web Crawler')
parser.add_argument('root_url', help='The root URL to start crawling from')
parser.add_argument('depth_limit', type=int, help='Recursion depth limit (positive integer)')
args = parser.parse_args()
if args.depth_limit < 1:
parser.error("Depth limit must be a positive integer.")
return args.root_url, args.depth_limit
def main():
"""
Main function to execute the web crawler.
:return:
"""
if len(sys.argv) != 3:
print("Usage: python main.py <root_url> <max_depth>")
sys.exit(1)
root_url, depth_limit = parse_arguments()
crawler = WebCrawler(root_url, depth_limit)
if crawler.root_url is None:
print(f"Invalid root URL: {root_url}")
sys.exit(1)
crawler.crawl()
if __name__ == '__main__':
main()