-
Notifications
You must be signed in to change notification settings - Fork 0
/
myScraper.py
104 lines (91 loc) · 2.6 KB
/
myScraper.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from time import sleep
from pynput.keyboard import Controller,Key
import win32clipboard as clip
from pynput.mouse import Button, Controller as MouseController
mouse = MouseController()
keyboard = Controller()
def shortCut(holdArray, press, wait = 0.2, wait1 = 0.2,wait2 = 0):
for hold in holdArray:
keyboard.press(hold)
sleep(wait)
keyboard.press(press)
sleep(wait1)
keyboard.release(press)
for hold in holdArray:
keyboard.release(hold)
sleep(wait2)
def pressRelease(key, wait = 0.1):
keyboard.press(key)
sleep(wait)
keyboard.release(key)
def keyboardPrint(string, wait = 0):
for i in string:
pressRelease(i, wait = 0)
sleep(wait)
def copyText(string):
clip.OpenClipboard()
clip.EmptyClipboard()
clip.SetClipboardText(string)
clip.CloseClipboard()
def savePageSelenium(browser,adress,saveAs = ""):
browser.get(adress)
sleep(2)
shortCut([Key.ctrl], 's')
sleep(0.6)
clip.OpenClipboard()
if saveAs == "":
shortCut([Key.ctrl], "s", wait2 = 0.4)
pressRelease(Key.enter)
saveAs = clip.GetClipboardData()
clip.CloseClipboard()
return saveAs
clip.EmptyClipboard()
clip.SetClipboardText(saveAs)
shortCut([Key.ctrl], "v")
pressRelease(Key.enter)
clip.CloseClipboard()
return saveAs
def savePage(saveAs = ""):
shortCut([Key.ctrl], 's')
sleep(0.6)
clip.OpenClipboard()
if saveAs == "":
shortCut([Key.ctrl], "s")
pressRelease(Key.enter)
saveAs = clip.GetClipboardData()
clip.CloseClipboard()
return saveAs
clip.EmptyClipboard()
clip.SetClipboardText(saveAs)
clip.CloseClipboard()
shortCut([Key.ctrl], "v")
pressRelease(Key.enter)
return saveAs
def clickOnElement(x,y):
mouse.position = (x,y) #1480, 40, 1480, 120
mouse.press(Button.left)
mouse.release(Button.left)
def getCurrentSrc():
clickOnElement(1480, 40)
sleep(0.1)
clickOnElement(1480,120)
sleep(2)
shortCut([Key.ctrl], "a")
sleep(1)
shortCut([Key.ctrl], "c")
sleep(0.3)
clip.OpenClipboard()
src = clip.GetClipboardData()
clip.CloseClipboard()
shortCut([Key.ctrl], "w")
return src
def copyAll():
try:
shortCut([Key.ctrl], "a")
sleep(1)
shortCut([Key.ctrl], "c")
clip.OpenClipboard()
value = clip.GetClipboardData()
clip.CloseClipboard()
except: value = ""
return value