Skip to content

Commit eb10561

Browse files
committed
two levels of link clicking done
1 parent b2b8a3d commit eb10561

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
257 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import pyautogui
2+
import pyperclip
3+
import logging
4+
5+
logging.basicConfig(
6+
level=logging.DEBUG, format=' %(asctime)s - %(levelname)s- %(message)s')
7+
"""
8+
There is also an optional region keyword argument, if you do not want a screenshot of the entire screen. You can pass a four-integer tuple of the left, top, width, and height of the region to capture:
9+
>>> im = pyautogui.screenshot(region=(0,0, 300, 400))
10+
11+
These "locate" functions are fairly expensive; they can take a full second to run. The best way to speed them up is to pass a region argument (a 4-integer tuple of (left, top, width, height)) to only search a smaller region of the screen instead of the full screen:
12+
>>> pyautogui.locateOnScreen('someButton.png', region=(0,0, 300, 400))
13+
14+
>>> button7location = pyautogui.locateOnScreen('calc7key.png', grayscale=True)
15+
16+
17+
left = 459,
18+
top = 124,
19+
width = 986,
20+
height = 913
21+
22+
left side In [2]: pyautogui.position()
23+
Out[2]: Point(x=459, y=412) x left
24+
25+
In [3]: pyautogui.position()
26+
Out[3]: Point(x=1443, y=416) 986 width
27+
28+
In [4]: pyautogui.position() top panel
29+
Out[4]: Point(x=466, y=128) height
30+
31+
In [5]: pyautogui.position()
32+
Out[5]: Point(x=462, y=125) y top
33+
34+
In [6]: pyautogui.position() bottom panel
35+
Out[6]: Point(x=439, y=1037)
36+
37+
Distance between close buttons horizontally 160
38+
39+
In [7]: pyautogui.position()
40+
Out[7]: Point(x=605, y=389)
41+
42+
In [8]: pyautogui.position()
43+
Out[8]: Point(x=765, y=385)
44+
45+
Distance between close buttons vertically 204
46+
47+
In [10]: pyautogui.position()
48+
Out[10]: Point(x=605, y=448)
49+
50+
In [11]: pyautogui.position()
51+
Out[11]: Point(x=605, y=652)
52+
53+
close button size region overapproximation: 40, 40
54+
In [20]: pyautogui.position()
55+
Out[20]: Point(x=591, y=546)
56+
57+
In [21]: pyautogui.position()
58+
Out[21]: Point(x=620, y=545)
59+
60+
61+
"""
62+
63+
pyautogui.PAUSE = 1
64+
# pyautogui.FAILSAFE = True
65+
numbers = ''
66+
"""
67+
68+
algo:
69+
- run program with delay of 5 seconds,
70+
- visit https://www.facebook.com/ads/preferences/?entry_product=ad_settings_screen
71+
- hover mouse on first advertiser name, but not on close button
72+
- take screenshot of present screen at region selection
73+
- find position of first close button, store this as firstCloseButtonPosition
74+
- Click on it
75+
- Move horizontally to next potential close button using relative close button distance, store increment countRight with index 0
76+
- move mouse horizontally from -2 to 2 to make the close button visible
77+
- take another screenshot at this button position, this time using overapproximation region to make things faster
78+
- if close button is visible, click on it, repeat horizontally
79+
- If countRight is equal to 5, move vertically down from firstCloseButtonPosition
80+
- go for see more procedure
81+
"""
82+
83+
import time
84+
time.sleep(5)
85+
86+
logging.debug('starting')
87+
88+
try:
89+
90+
firstCloseButton = pyautogui.locateOnScreen(
91+
'close.png', region=(459, 124, 986, 913), grayscale=True)
92+
firstCloseButtonPosition = pyautogui.center(firstCloseButton)
93+
for j in range(2):
94+
logging.debug("clicking at " + str(firstCloseButtonPosition))
95+
pyautogui.moveTo(firstCloseButtonPosition)
96+
# pyautogui.click(firstCloseButtonPosition)
97+
logging.debug("clicking at: " + str(firstCloseButtonPosition))
98+
99+
for i in range(5):
100+
logging.debug("i = " + str(i))
101+
pyautogui.move(120, 0)
102+
# pyautogui.move(0, -60)
103+
x, y = pyautogui.position()
104+
current_position_location = pyautogui.locateOnScreen(
105+
'close.png',
106+
region=(x - 100, y - 100, 200, 200),
107+
grayscale=True)
108+
current_position = pyautogui.center(current_position_location)
109+
pyautogui.moveTo(current_position)
110+
# pyautogui.click()
111+
logging.debug("clicking at " + str(current_position))
112+
113+
logging.debug("horiontal done, returning at position: " +
114+
str(firstCloseButtonPosition))
115+
116+
firstCloseButtonPosition = firstCloseButtonPosition[
117+
0], firstCloseButtonPosition[1] + 204
118+
logging.debug("vertical adjustment done, returning at position: " +
119+
str(firstCloseButtonPosition))
120+
pyautogui.moveTo(firstCloseButtonPosition)
121+
pyautogui.locateOnScreen('seemore.png')
122+
except Exception as e:
123+
124+
print(e)
1.03 KB
Loading

0 commit comments

Comments
 (0)