-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTorScrape.py
More file actions
76 lines (58 loc) · 2.03 KB
/
TorScrape.py
File metadata and controls
76 lines (58 loc) · 2.03 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import time
import pyautogui
import urllib.parse
BASE_DIRECTORY = "PATH\TO\YOUR\DOWNLOAD\DIRCTORY"
TEXT_FILE = "PATH\TO\YOUR\TEXT\FILE.TXT"
BASE_URL = input("Enter the base URL (e.g., http://example.onion/): ").strip()
def create_folder_if_not_exists(folder_path):
if not os.path.exists(folder_path):
os.makedirs(folder_path)
def navigate_to_url(url):
pyautogui.hotkey('ctrl', 'l')
time.sleep(1)
pyautogui.typewrite(url)
time.sleep(1)
pyautogui.press('enter')
def save_page(file_path):
pyautogui.hotkey('ctrl', 's')
time.sleep(2)
pyautogui.typewrite(file_path)
time.sleep(1)
pyautogui.press('enter')
def process_url(url):
parsed_url = urllib.parse.urlparse(url)
path_parts = parsed_url.path.strip('/').split('/')
subfolder_path = os.path.join(BASE_DIRECTORY, *path_parts[:-1])
create_folder_if_not_exists(subfolder_path)
# Determine file name
file_name = f"{path_parts[-1] or 'index'}.html"
return subfolder_path, file_name
def main():
with open(TEXT_FILE, 'r') as file:
links = [line.strip() for line in file if line.strip()]
if not links:
print("No links found in the text file.")
return
# Navigate to the first link immediately
first_url = links[0]
if not first_url.startswith(BASE_URL):
first_url = urllib.parse.urljoin(BASE_URL, first_url)
print(f"Navigating to: {first_url}")
navigate_to_url(first_url)
time.sleep(5)
for index, url in enumerate(links):
if not url.startswith(BASE_URL):
url = urllib.parse.urljoin(BASE_URL, url)
print(f"Processing: {url}")
subfolder_path, file_name = process_url(url)
file_path = os.path.join(subfolder_path, file_name)
if index == 0:
print("Skipping save for the initial navigation to ensure proper workflow.")
continue
navigate_to_url(url)
time.sleep(15)
save_page(file_path)
print(f"Saved: {file_path}")
if __name__ == "__main__":
main()