-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaver.py
81 lines (57 loc) · 1.85 KB
/
saver.py
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
77
78
79
80
81
import pyautogui
import time
import pyperclip
# Giving time for the user to open the chrome tab and place the cursor on the address bar
# time.sleep(5)
# print(pyautogui.position())
'''
When you are running the script for the first time
then comment the below part of the code completely to get the
position of the address bar of the chrome browser
on your screen, and uncomment the above 2 lines of code
and place the cursor on the chorme tab's address bar
to retrieve the x and y coordinates.
The index values of the cursor would be printed in the console
and use them in the code below for the click function
'''
# Specify the path for the text file containing the links
path = r"<path to the txt file to save all the links>"
# Wait for some time to change to the chrome browser
time.sleep(5)
links = []
# This number defines the max number of duplicate tabs allowed to be saved
thresh = 5
# Keeps the count of the duplicate tabs found so far
count = 0
total = 0
while True:
pyautogui.click(665, 81)
# Select all the text in the link box in the chrome
pyautogui.hotkey("ctrl", "a")
# Copy the selected link
pyautogui.hotkey("ctrl", "c")
link = pyperclip.paste().strip()
"""
If there is an empty string in the
clipboard the string pyperclip.paste()
gets returned, so the condition is framed on top of that
"""
# If there is a new tab neglect it
if link == "pyperclip.paste()":
pass
else:
# Check if the link already exists in the existing links or not
if link in links:
count += 1
if count == thresh:
break
else:
total += 1
links.append(link)
pyautogui.hotkey("ctrl", "tab")
f = open(path, "w+")
for i in links:
f.write(str(i) + "\n")
f.close()
print(f"\nTotally {total} link(s) were saved")
print("Successfully saved the all links!!!")