-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
1444 lines (1401 loc) · 86.2 KB
/
Copy pathbot.py
File metadata and controls
1444 lines (1401 loc) · 86.2 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from playwright.sync_api import Playwright, sync_playwright, expect
from datetime import datetime, timedelta
from pathlib import Path
from twocaptcha import TwoCaptcha
import mysql.connector
from mysql.connector import Error
#from openpyxl import load_workbook, Workbook
import sys
import time
import os
import re
ws_data_hora_login = None
def VerificaClientRecaptcha(page):
ws_find_recaptcha = page.evaluate("""function findRecaptchaClients()
{ // eslint-disable-next-line camelcase
if (typeof (___grecaptcha_cfg) !== 'undefined') {
// eslint-disable-next-line camelcase, no-undef
return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => {
const data = { id: cid, version: cid >= 10000 ? 'V3' : 'V2' };
const objects = Object.entries(client).filter(([_, value]) => value && typeof value === 'object');
objects.forEach(([toplevelKey, toplevel]) => {
const found = Object.entries(toplevel).find(([_, value]) => (
value && typeof value === 'object' && 'sitekey' in value && 'size' in value
));
if (typeof toplevel === 'object' && toplevel instanceof HTMLElement && toplevel['tagName'] === 'DIV'){
data.pageurl = toplevel.baseURI;
}
if (found) {
const [sublevelKey, sublevel] = found;
data.sitekey = sublevel.sitekey;
const callbackKey = data.version === 'V2' ? 'callback' : 'promise-callback';
const callback = sublevel[callbackKey];
if (!callback) {
data.callback = null;
data.function = null;
} else {
data.function = callback;
const keys = [cid, toplevelKey, sublevelKey, callbackKey].map((key) => `['${key}']`).join('');
data.callback = `___grecaptcha_cfg.clients${keys}`;
}
}
});
return data;
});
}
return [];
}""")
ws_recaptcha = ws_find_recaptcha[0]['callback']
#ws_recaptcha2 = ws_find_recaptcha[1]['callback']
return ws_recaptcha #, ws_recaptcha2
def VerificaHoraLogin():
data = datetime.today()
dt_hora_login = data.strftime('%Y-%m-%d 20:00')
return dt_hora_login
def VerificaDataHora():
data = datetime.today()
dt_hora_atual = data.strftime('%Y-%m-%d %H:%M')
return dt_hora_atual
def VerificaHora():
data = datetime.today()
hora_atual = data.strftime('%H:%M')
return hora_atual
def VerificaHoraSegundo():
data = datetime.today()
hora_atual_segundo = data.strftime('%H:%M:%S')
return hora_atual_segundo
def ReiniciaBrowser(p,browser,page,context):
#page.close()
#p.stop()
p = sync_playwright().start()
browser = p.chromium.launch(headless=False)
#browser = p.firefox.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.set_default_navigation_timeout(60000)
page.goto("https://www.freepik.com/")
return p,browser,page,context
def ReCaptcha(nome_pagina):
global id_captcha
api_key = "c934c0c66383af7c6456a6ca451866b9"
config = {
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
'apiKey': api_key,
'softId': 123,
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
}
solver = TwoCaptcha(**config)
try:
result = solver.recaptcha(
sitekey='6LfEmSMUAAAAAEDmOgt1G7o7c53duZH2xL_TXckC',
url= nome_pagina,
invisible=1,
enterprise=0
# proxy={
# 'type': 'HTTPS',
# 'uri': 'login:password@IP_address:PORT'
# }
)
except Exception as e:
if e == '500':
ReCaptcha(nome_pagina)
except ValidationException as e:
# invalid parameters passed
print(e)
except NetworkException as e:
# network error occurred
print(e)
except ApiException as e:
# api respond with error
print(e)
except TimeoutException as e:
# captcha is not solved so far
print(e)
else:
id_captcha = result['code']
if id_captcha == '':
time.sleep(10)
ReCaptcha(nome_pagina)
# sys.exit('result: ' + str(result))
def ConectaBD():
global cursor
global con
con = mysql.connector.connect(host='localhost', database='designerclub', user='root', password='off!')
if con.is_connected():
cursor = con.cursor(dictionary=True)
def DesconectaBD():
if con.is_connected():
cursor.close()
con.close()
def CarregaLogin(count,p,browser,page,context,username,password, ws_rodou_captcha):
if count == 0:
x = count+1
else:
x = count
ws_nome_frame = ""
erro_login_download = ""
qtdDownload = 0
for i in range(x):
try:
nome_pagina = page.url
ws_reset_page = False
if ws_rodou_captcha == True:
ws_ReiniciaBrowser = ReiniciaBrowser(p,browser,page,context)
if ws_ReiniciaBrowser[0] != []:
p = ws_ReiniciaBrowser[0]
browser = ws_ReiniciaBrowser[1]
page = ws_ReiniciaBrowser[2]
context = ws_ReiniciaBrowser[3]
ws_rodou_captcha = False
ws_reset_page = True
#botao_login = page.querySelector('xpath=//a[@href="https://br.freepik.com/profile/login"]')
#page.wait_for_selector('#navigation > div > div > div > div.gr-auth__disconnected > a:nth-child(1)' )
page.wait_for_timeout(3000)
page.get_by_role("link", name="Log in").click()
#page.locator('"Log in"').wait_for(state='visible', timeout=60000)
page.wait_for_timeout(3000)
#page.locator('"Log in"').click()
#page.wait_for_timeout(3000)
page.wait_for_load_state()
#page.wait_for_timeout(3000)
#time.sleep(2)
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[1]/a[1]')
#page.wait_for_timeout(3000)
ws_xpath_login = 'xpath=//*[@id="log-in"]/div[1]/form/div[4]/button'
if count >= 1 and ws_reset_page == False:
ws_xpath_login = 'xpath=//*[@id="log-in"]/div[1]/form/div[4]/button'
page.locator('"Use another account"').click()
#page.locator('"Continue with email"').wait_for(state='visible', timeout=60000)
page.wait_for_timeout(3000)
page.get_by_role("button", name=" Continue with email").click()
#page.locator('"Email"').wait_for(state='visible', timeout=60000)
nome_pagina = page.url
#ws_nome_cliente = ws_ClientRecaptcha[0]
#ws_nome_cliente2 = ws_ClientRecaptcha[1]
page.get_by_label("Email").click()
page.get_by_label("Email").fill(username)
#page.fill('"Email"', username)
page.wait_for_timeout(3000)
ws_ClientRecaptcha = VerificaClientRecaptcha(page)
page.get_by_label("Password").click()
page.get_by_label("Password").fill(password)
#page.fill('"Password"', password)
#page.click('xpath=//*[@id="log-in"]/div[1]/form/div[3]/label/input')
page.wait_for_timeout(3000)
page.click(ws_xpath_login)
#log-in > div.native-sign > form > div.form-item.submit > button
#page.wait_for_timeout(6000)
page.wait_for_url("https://www.freepik.com/?log-in=email")
page.wait_for_timeout(5000)
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[1]/button')
try:
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
page.get_by_role("button", name="avatar").click()
#page.wait_for_selector('#icons_downloaded_counters')
page.get_by_role("link", name="Downloads").is_visible
except Exception as e:
ws_msg_erro = e.message
ws_erro = "Timeout 60000ms"
result_erro = ws_msg_erro.find(ws_erro)
if result_erro != -1:
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
#page.locator('.avatar--xs > img:nth-child(1)').click()
page.wait_for_selector('#icons_downloaded_counters')
#page.wait_for_timeout(3000)
try:
page.reload()
page.get_by_role("button", name="avatar").click()
#page.wait_for_selector('#icons_downloaded_counters')
page.get_by_role("link", name="Downloads").is_visible
#radix-\:r3\: > div > div:nth-child(3) > div > div > div
#radix-\:r3\: > div > div:nth-child(3) > div > div > div
campo_download = page.locator('#radix-\:r3\: > div > div:nth-child(3) > div > div > div')
#campo_download = page.locator('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
#campo_download = page.query_selector('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@class="badge badge--pill badge--gray mg-right-lv2 push-right"]')
qtdDownload = campo_download.text_content()
except Exception as erro_cont_download:
campo_download = page.locator('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
qtdDownload = campo_download.text_content()
#page.wait_for_selector('#navigation > div > div > div > div.gr-auth__connected > div > div.popover.popover--mobile-fullscreen.popover--bottom-right.popover--width-xs.block.gr-auth__popover.active > div > div > ul.font-sm.line-height-sm.uppercase.mg-none-i > li > button')
#page.wait_for_timeout(5000)
page.locator('"Log out"').click()
page.wait_for_load_state()
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div/div/div/ul[3]/li/button')
except Exception as e:
ws_msg_erro = e.message
ws_erro = "Timeout 60000ms"
result_erro = ws_msg_erro.find(ws_erro)
if result_erro != -1:
frame = page.frame(url=r".*google.com/recaptcha/api2/bframe*")
if frame != None:
ws_nome_frame = frame.name
if ws_nome_frame != "":
#try:
ws_rodou_captcha = True
page.close()
browser.close()
p.stop()
p = sync_playwright().start()
browser = p.chromium.launch(headless=False)
#browser = p.firefox.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.set_default_navigation_timeout(60000)
page.goto("https://www.freepik.com/profile/login")
#page.goto("https://www.freepik.com/")
#page.wait_for_load_state()
#page.get_by_role("link", name="Log in").click()
#page.wait_for_timeout(3000)
#ws_xpath_login = 'xpath=//*[@id="log-in"]/div[1]/form/div[4]/button'
#page.get_by_role("button", name=" Continue with email").click()
#page.wait_for_timeout(3000)
nome_pagina = page.url
page.locator('xpath=//*[@id="login-username"]').click()
#page.get_by_label("Email").click()
page.locator('xpath=//*[@id="login-username"]').fill(username)
#page.get_by_label("Email").fill(username)
page.wait_for_timeout(3000)
ws_ClientRecaptcha = VerificaClientRecaptcha(page)
page.locator('xpath=//*[@id="login-password"]').click()
#page.get_by_label("Email").click()
page.locator('xpath=//*[@id="login-password"]').fill(password)
page.wait_for_timeout(3000)
ReCaptcha(nome_pagina)
#page.wait_for_timeout(3000)
page.locator('xpath=//*[@id="auth-login-form-1"]').click()
#page.click(ws_xpath_login)
page.evaluate(f'document.getElementById("g-recaptcha-response").innerHTML="{id_captcha}";')
#page.evaluate(f"{ws_recaptcha}('{id_captcha}');")
#page.evaluate(f"{ws_recaptcha2}('{id_captcha}');")
page.evaluate(f"{ws_ClientRecaptcha[0]}('{id_captcha}');")
#page.evaluate(f"{ws_ClientRecaptcha[1]}('{id_captcha}');")
#page.evaluate(f"___grecaptcha_cfg.clients['0']['Z']['Z']['callback']('{id_captcha}');")
#log-in > div.native-sign > form > div.form-item.submit > button
#page.wait_for_timeout(6000)
page.wait_for_url("https://www.freepik.com/?log-in=email")
page.wait_for_timeout(5000)
try:
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
page.wait_for_selector('#icons_downloaded_counters')
except Exception as e:
ws_msg_erro = e.message
ws_erro = "Timeout 60000ms"
result_erro = ws_msg_erro.find(ws_erro)
if result_erro != -1:
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
#page.locator('.avatar--xs > img:nth-child(1)').click()
page.wait_for_selector('#icons_downloaded_counters')
#page.wait_for_timeout(3000)
campo_download = page.locator('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@class="badge badge--pill badge--gray mg-right-lv2 push-right"]')
qtdDownload = campo_download.text_content()
page.wait_for_selector('#navigation > div > div > div > div.gr-auth__connected > div > div.popover.popover--mobile-fullscreen.popover--bottom-right.popover--width-xs.block.gr-auth__popover.active > div > div > ul.font-sm.line-height-sm.uppercase.mg-none-i > li > button')
#page.wait_for_timeout(5000)
page.locator('"Log out"').click()
page.wait_for_load_state()
#page.wait_for_timeout(5000)
page.close()
browser.close()
p.stop()
#browser.close()
# except Exception as erro_login_download:
# time.sleep(10)
# try:
# page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
# page.wait_for_selector('#icons_downloaded_counters')
# except Exception as e:
# ws_msg_erro = e.message
# ws_erro = "Timeout 30000ms"
# result_erro = ws_msg_erro.find(ws_erro)
# if result_erro != -1:
# page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
# page.wait_for_selector('#icons_downloaded_counters')
#page.wait_for_timeout(3000)
# campo_download = page.locator('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@class="badge badge--pill badge--gray mg-right-lv2 push-right"]')
# qtdDownload = campo_download.text_content()
# page.wait_for_selector('#navigation > div > div > div > div.gr-auth__connected > div > div.popover.popover--mobile-fullscreen.popover--bottom-right.popover--width-xs.block.gr-auth__popover.active > div > div > ul.font-sm.line-height-sm.uppercase.mg-none-i > li > button')
#page.wait_for_timeout(5000)
# page.locator('"Logout"').click()
# page.wait_for_load_state()
# page.close()
# browser.close()
# p.stop()
else:
page.reload()
page.wait_for_load_state()
else:
page.close()
browser.close()
p.stop()
#ws_ReiniciaBrowser = ReiniciaBrowser(p,browser,page,context)
#if ws_ReiniciaBrowser[0] != []:
# p = ws_ReiniciaBrowser[0]
# browser = ws_ReiniciaBrowser[1]
# page = ws_ReiniciaBrowser[2]
# context = ws_ReiniciaBrowser[3]
#page.locator('"Log in"').wait_for(state='visible', timeout=60000)
#page.locator('"Log in"').click()
#page.wait_for_load_state()
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[1]/a[1]')
#page.wait_for_timeout(3000)
# time.sleep(3)
# if count >= 1 and ws_reset_page == False:
# page.locator('"Unlink account"').click()
# page.wait_for_selector('#login-username')
# nome_pagina = page.url
# ws_ClientRecaptcha = VerificaClientRecaptcha(page)
#ws_nome_cliente = ws_ClientRecaptcha[0]
#ws_nome_cliente2 = ws_ClientRecaptcha[1]
# page.fill('xpath=//input[@name="username"]', username)
#page.wait_for_timeout(3000)
# page.fill('xpath=//input[@name="password"]', password)
#page.wait_for_timeout(3000)
# page.click('xpath=//*[@id="auth-login-form-1"]')
#page.wait_for_timeout(6000)
# page.wait_for_url("https://www.freepik.com/")
#page.wait_for_timeout(5000)
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[1]/button')
#page.mouse.move(24, 24)
#page.mouse.down()
#page.mouse.up()
# try:
# page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
# page.wait_for_selector('#icons_downloaded_counters')
# except Exception as e:
# ws_msg_erro = e.message
# ws_erro = "Timeout 30000ms"
# result_erro = ws_msg_erro.find(ws_erro)
# if result_erro != -1:
# page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
# page.wait_for_selector('#icons_downloaded_counters')
#page.wait_for_timeout(3000)
# campo_download = page.locator('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@id="icons_downloaded_counters"]')
#campo_download = page.query_selector('xpath=//*[@class="badge badge--pill badge--gray mg-right-lv2 push-right"]')
# qtdDownload = campo_download.text_content()
# page.wait_for_selector('#navigation > div > div > div > div.gr-auth__connected > div > div.popover.popover--mobile-fullscreen.popover--bottom-right.popover--width-xs.block.gr-auth__popover.active > div > div > ul.font-sm.line-height-sm.uppercase.mg-none-i > li > button')
#page.wait_for_timeout(5000)
# page.locator('"Logout"').click()
# page.wait_for_load_state()
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div/div/div/ul[3]/li/button')
finally:
if qtdDownload == 0:
#page.click('//*[@id="notification-center-menu__trigger-icon"]/i')
print(erro_login_download)
return
else:
return qtdDownload, p, page, context, browser, ws_rodou_captcha
def VerificaLogin():
global ws_nome_conta
try:
ws_erro = ""
ConectaBD()
dt_hora_atual = VerificaDataHora()
hora_atual_segundo = VerificaHoraSegundo()
args = [dt_hora_atual,0,0]
results_args = cursor.callproc('Consulta_Todos_Login', args)
y = results_args['Consulta_Todos_Login_arg2']
z = results_args['Consulta_Todos_Login_arg3']
if z != 0:
results = [r.fetchall() for r in cursor.stored_results()]
count = 0
if results[0] != []:
ws_rodou_captcha = False
p = sync_playwright().start()
browser = p.chromium.launch(headless=False)
#browser = p.firefox.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.set_default_navigation_timeout(60000)
page.goto("https://www.freepik.com/")
for i in range(y):
for row in results:
x = row[count]
username = x['Login']
password = x['Senha']
ws_data_hora_login = x['data_atualizacao_login']
duracao = "03:00:00"
horas, minutos, segundos = map(int, duracao.split(':'))
horas2, minutos2, segundos2 = map(int, hora_atual_segundo.split(':'))
duracao = timedelta(hours=horas, minutes=minutos, seconds=segundos)
duracao2 = timedelta(hours=horas2, minutes=minutos2, seconds=segundos2)
ws_xx_hora = ws_data_hora_login + duracao
ws_xx_hora2 = ws_data_hora_login.strftime('%H:%M:%S')
ws_diff_hora = ws_xx_hora.strftime('%H:%M:%S')
ws_nome_conta = x['nome_conta']
if hora_atual_segundo <= ws_diff_hora:
break
else:
ws_retorno_login = CarregaLogin(count,p,browser,page, context,username,password, ws_rodou_captcha)
if ws_retorno_login[0] != []:
qtdDownload = ws_retorno_login[0]
p = ws_retorno_login[1]
page = ws_retorno_login[2]
context = ws_retorno_login[3]
browser = ws_retorno_login[4]
ws_rodou_captcha = ws_retorno_login[5]
duracao = None
ws_diff_hora = None
args = [username, qtdDownload, dt_hora_atual]
results_args2 = cursor.callproc('Atualiza_QtdDownload_Login', args)
count += 1
except Error as erro:
print("Falha ao inserir dados no MySQL: {}".format(erro))
ws_erro = erro
return
except Exception as e:
ws_erro = e
print(e)
return
finally:
if ws_erro == "":
if ws_rodou_captcha == False:
browser.close()
p.stop()
args = [0,0,0,0,0]
results_args = cursor.callproc('Consultar_Qtd_Download_Login', args)
username = results_args['Consultar_Qtd_Download_Login_arg1']
password = results_args['Consultar_Qtd_Download_Login_arg2']
ws_hora_inicio_freepik = results_args['Consultar_Qtd_Download_Login_arg3']
ws_hora_fim_freepik = results_args['Consultar_Qtd_Download_Login_arg4']
ws_nome_conta = results_args['Consultar_Qtd_Download_Login_arg5']
DesconectaBD()
if username != None:
PikDownload(username, password, ws_hora_inicio_freepik, ws_hora_fim_freepik)
else:
print("Não há mais conta Freepik disponível")
return
#path_login = os.path.dirname(__file__)
#path_excel = path_login + "\Login.xlsx"
#wb = xl.load_workbook(filename = path_excel)
#ws = wb.active
#x = 4
#if ws.cell(row=2, column=4).value != data_em_texto:
# for i in range(2, ws.max_row+1):
# for j in range(1, ws.max_column+1):
# if ws.cell(row=i, column=j).value == "" :
# break
# else:
# if j < 2:
# username = ws.cell(row=i, column=j).value
# elif j == 2:
# password = ws.cell(row=i, column=j).value
# Login(username, password)
# if j >2:
# ws.cell(row=i, column=j).value = qtdDownload
# ws.cell(row=i, column=x).value = data_em_texto
# wb.save(filename = path_excel)
#def GravaImagem(username, path_arq_down, p, page, browser, ws_ClientRecaptcha, ws_hora_inicio_freepik, ws_hora_fim_freepik):
def GravaImagem(username, path_arq_down, p, page, browser, ws_hora_inicio_freepik, ws_hora_fim_freepik):
ws_verifica = True
ws_verifica_horario = False
erro = ""
ws_ia_imagem = False
qtdDownload = 0
ws_nome_frame = ""
ws_link_download = ""
erro_captcha = ""
erro_download = ""
ws_link_xpath = ""
ws_count_typeerror = 0
ws_primeiro_click = False
while ws_verifica == True:
try:
ConectaBD()
hora_atual = VerificaHora()
if hora_atual >= ws_hora_inicio_freepik and hora_atual <= ws_hora_fim_freepik and ws_verifica_horario == False:
cursor.callproc('Atualizar_Resetar_QtdDownload_Login')
ws_verifica_horario = True
elif hora_atual >= ws_hora_fim_freepik:
ws_verifica_horario = False
args = [0]
results_args = cursor.callproc('Consultar_Todos_Download', args)
ws_count = results_args['Consultar_Todos_Download_arg1']
count = 0
results = [r.fetchall() for r in cursor.stored_results()]
if results[0] != []:
for i in range(ws_count):
for row in results:
x = row[count]
ws_id_cliente = x['idClientes']
ws_nome_link_imagem = x['nome_link_imagem']
ws_tipo_arquivo_link = x['tipo_arquivo_link']
args = [ws_id_cliente,0]
results_args = cursor.callproc('Consultar_Nome_Cliente', args)
ws_nome_cliente = results_args['Consultar_Nome_Cliente_arg2']
caminho = path_arq_down + "\\" + ws_nome_cliente
if not os.path.exists(caminho):
os.makedirs(caminho)
page.goto(ws_nome_link_imagem)
ws_nome_pagina_convertida = page.url
ws_count_link = ws_nome_pagina_convertida.find('ai-image')
ws_count_link = ws_nome_pagina_convertida.find('-ai-') or ws_nome_pagina_convertida.find('-ia-')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('premium-photo')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('free-photo')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('fotos-gratis')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('premium-vector')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('free-vector')
if ws_count_link == -1:
ws_count_link = ws_nome_pagina_convertida.find('fotos-premium')
ws_count_link_foto_premium = ws_nome_pagina_convertida.find('premium-photo')
if ws_count_link_foto_premium == -1:
ws_count_link_foto_premium = ws_nome_pagina_convertida.find('fotos-premium')
#ws_count_link = ws_nome_pagina_convertida.find('-ai-') or ws_nome_pagina_convertida.find('br.freepik.com')
#if ws_count_link != -1:
# ws_count_link =
#ws_count_link = ws_nome_pagina_convertida.find('_ai_') or ws_nome_pagina_convertida.find('_ia_')
#ws_count_link = ws_nome_pagina_convertida.find('-ai_') or ws_nome_pagina_convertida.find('-ia_')
#ws_count_link = ws_nome_link_imagem.find('ai-image')
#ws_count_link = ws_nome_link_imagem.find('ai') or ws_nome_link_imagem.find('ia')
page.wait_for_load_state()
if ws_count_link != -1:
try:
#page.get_by_role("button", name="Original").wait_for(state='visible', timeout=25000)
#if ws_primeiro_click == False:
# expect(page.locator("div:nth-child(8) > div > div")).to_be_visible()
# page.get_by_role("button", name="Got it").first.click()
# ws_primeiro_click = True
page.reload()
page.get_by_role("button", name="avatar").click()
#page.wait_for_timeout(3000)
page.get_by_role("button", name="avatar").click()
except Exception as erro_download:
try:
page.get_by_role("button", name=" Download").wait_for(state='visible', timeout=25000)
ws_count_link = -1
except Exception as erro_download:
#ProximaConta(p, page, browser)
args = [ws_id_cliente,ws_nome_link_imagem]
cursor.callproc('Atualiza_Link_Invalido', args)
break
else:
try:
#//*[@id="radix-:r3:"]/div/div[1]/div/p[2]
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
campo_login = page.locator('xpath=//*[@id="navigation"]/div/div/div[1]/div[2]/div/div[2]/div/div/div/div[2]/span[2]')
ws_deslogado = campo_login.text_content()
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
if ws_deslogado == '':
page.click('xpath=//*[@id="main"]')
ProximaConta(p, page, browser)
except Exception as erro_download:
try:
expect(page.get_by_role("link", name="Log in")).to_be_visible()
ProximaConta(p, page, browser)
break
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
#campo_login = page.locator('xpath=//*[@id="navigation"]/div/div/div[1]/div[2]/div/div[2]/div/div/div/div[2]/span[2]')
#ws_deslogado = campo_login.text_content()
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
#if ws_deslogado == '':
# page.click('xpath=//*[@id="main"]')
# ProximaConta(p, page, browser)
#else:
# page.click('xpath=//*[@id="main"]')
# page.reload()
# page.wait_for_load_state()
except Exception as erro_download:
try:
page.reload()
page.wait_for_load_state()
page.get_by_role("button", name=" Download").wait_for(state='visible', timeout=25000)
except Exception as erro_download:
args = [ws_id_cliente,ws_nome_link_imagem]
cursor.callproc('Atualiza_Link_Invalido', args)
break
#page.locator('"Log in"').click()
#page.wait_for_load_state()
#ws_msg_erro = "Timeout 60000ms"
#raise Exception()
#page.wait_for_timeout(5000)
ws_temp_numero_link = ws_nome_link_imagem.split('_')
ws_temp_nome_link = ws_temp_numero_link[0].split('/')
ws_temp2_numero_link = ws_temp_numero_link[1].split('.')
ws_numero_link = ws_temp2_numero_link[0]
#nomearquivo = page.inner_text('xpath=//*[@id="main"]/section/footer/div[1]/div/div/h1')
#nomearquivo = page.inner_text('xpath=//*[@id="main"]/div/div[3]/h1')
nomearquivo = ws_temp_nome_link[4]
nomearquivo = nomearquivo + "_" + ws_numero_link
ws_count_arq = len(nomearquivo)
if ws_count_arq > 200:
nomearquivo2 = ws_temp_nome_link[4]
nomearquivo = nomearquivo2[:200]
nomearquivo = nomearquivo + "_" + ws_numero_link
#ws_count_arq1 = nomearquivo.count('"')
#ws_count_arq2 = nomearquivo.count('/')
#ws_count_arq3 = nomearquivo.count('.')
#if (ws_count_arq1 or
# ws_count_arq2 or
# ws_count_arq3 >= 1):
# nomearquivo = ws_temp_nome_link[4]
#tipoarquivo = page.inner_text('xpath=//*[@id="main"]/section/aside/div[2]/div[2]/div/div[1]/h6/span')
if ws_tipo_arquivo_link == "JPG":
nomearquivo = nomearquivo + ".jpg"
path_arq_file = os.path.join(caminho, nomearquivo)
#caminhobotao = 'xpath=//*[@id="main"]/section/aside/div[2]/div[1]/div/div[3]/div[1]'
elif ws_tipo_arquivo_link == "EPS":
nomearquivo = nomearquivo + ".zip"
path_arq_file = os.path.join(caminho, nomearquivo)
#caminhobotao = 'xpath=//*[@id="main"]/section/aside/div[2]/div[1]/div/a'
elif ws_tipo_arquivo_link == "PSD":
nomearquivo = nomearquivo + ".zip"
path_arq_file = os.path.join(caminho, nomearquivo)
#caminhobotao = 'xpath=//*[@id="main"]/section/aside/div[2]/div[1]/div/a'
elif ws_tipo_arquivo_link == "ZIP":
nomearquivo = nomearquivo + ".zip"
path_arq_file = os.path.join(caminho, nomearquivo)
fileObj = Path(path_arq_file)
verificadownload = fileObj.is_file()
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div/button/div/span[1]/img')
try:
if ws_count_link != -1:
page.reload()
page.get_by_role("button", name="avatar").click()
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r3:"]/div/div[3]/div/div/div'
if ws_count_link_premium== -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_selector('#radix-\:r1\: > div > div:nth-child(3) > div > div > div')
#page.wait_for_timeout(3000)
#page.wait_for_selector('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
page.wait_for_selector(ws_link_xpath)
#page.wait_for_selector('//*[@id="radix-:r4:"]/div/div[3]/div/div/div')
#page.wait_for_timeout(3000)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1:
try:
page.get_by_role("button", name="View prompt").wait_for(state='visible', timeout=25000)
page.wait_for_selector('//*[@id="radix-:r8:"]/div/div[3]/div/div/div')
except Exception as e:
page.wait_for_selector('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
else:
#page.wait_for_selector('//*[@id="radix-:r4:"]/div/div[3]/div/div/div')
#page.wait_for_selector('#radix-\:r1\: > div > div:nth-child(3) > div > div > div')
page.wait_for_selector('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
else:
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
page.wait_for_selector('#icons_downloaded_counters')
except Exception as e:
ws_msg_erro = e.message
ws_erro = "Timeout 30000ms"
result_erro = ws_msg_erro.find(ws_erro)
if result_erro != -1:
#page.wait_for_timeout(3000)
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_timeout(3000)
#page.wait_for_selector('//*[@id="radix-:r4:"]/div/div[3]/div/div/div')
#page.wait_for_selector('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
page.wait_for_selector(ws_link_xpath)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1:
try:
page.get_by_role("button", name="View prompt").wait_for(state='visible', timeout=25000)
page.wait_for_selector('//*[@id="radix-:r8:"]/div/div[3]/div/div/div')
except Exception as e:
page.wait_for_selector('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
else:
page.wait_for_selector('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
#page.wait_for_timeout(3000)
try:
if ws_count_link != -1:
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r3:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_timeout(3000)
#campo_download = page.locator('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
campo_download = page.locator(ws_link_xpath)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1:
try:
page.get_by_role("button", name="View prompt").wait_for(state='visible', timeout=25000)
campo_download = page.locator('//*[@id="radix-:r8:"]/div/div[3]/div/div/div')
except Exception as e:
campo_download = page.locator('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
else:
campo_download = page.locator('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
else:
campo_download = page.locator('xpath=//*[@class="badge badge--pill badge--gray mg-right-lv2 push-right"]')
except Exception as e:
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_timeout(3000)
#campo_download = page.locator('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
campo_download = page.locator(ws_link_xpath)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1:
try:
page.get_by_role("button", name="View prompt").wait_for(state='visible', timeout=25000)
campo_download = page.locator('//*[@id="radix-:r8:"]/div/div[3]/div/div/div')
except Exception as e:
campo_download = page.locator('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
else:
campo_download = page.locator('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
try:
qtdDownload = campo_download.text_content()
except Exception as e:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
if ws_count_link_premium != -1:
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
if ws_count_link_premium != -1:
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[4]/div/div/div'
campo_download = page.locator(ws_link_xpath)
qtdDownload = campo_download.text_content()
ws_find_help = qtdDownload.find('Help')
if ws_find_help != -1:
qtdDownload = str(qtdDownload).replace('Help', '')
if ws_count_link != -1:
page.get_by_role("button", name="avatar").click()
else:
page.click('xpath=//*[@id="main"]')
#page.get_by_role("button", name="avatar").click()
#page.get_by_role("button", name=ws_nome_conta).click()
nome_pagina = page.url
if verificadownload == False and qtdDownload != "100/100":
try:
if ws_count_link_foto_premium != -1:
page.get_by_text("Download", exact=True).click()
elif ws_count_link != -1:
page.get_by_text("Download", exact=True).click()
#page.get_by_role("button", name=" Download").wait_for(state='visible', timeout=25000)
#page.get_by_role("button", name=" Download").click()
else: #//*[@id="__next"]/div[3]/div[1]/div[3]/div/div/div/div/a/text()
#page.get_by_role("link", name="Download").wait_for(state='visible', timeout=25000)
#page.get_by_text("Download", exact=True).click()
page.get_by_role("button", name=" Download").wait_for(state='visible', timeout=25000)
page.get_by_role("button", name=" Download").click()
with page.expect_download(timeout=60000) as download_info:
download = download_info.value
download_erro = download.failure()
if download_erro == None:
path = download.path()
download.save_as(path_arq_file)
if os.stat(path_arq_file).st_size == 0:
os.remove(path_arq_file)
DesconectaBD()
GravaImagem(username, path_arq_down, p, page, browser, ws_hora_inicio_freepik, ws_hora_fim_freepik)
#GravaImagem(username, path_arq_down, p, page, browser, ws_ClientRecaptcha, ws_hora_inicio_freepik, ws_hora_fim_freepik)
args = [ws_id_cliente,ws_nome_link_imagem, nomearquivo]
cursor.callproc('Atualizar_Nome_Arquivo_Lista', args)
#page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div/button/div/span[1]/img')
try:
if ws_count_link != -1:
page.reload()
page.get_by_role("button", name="avatar").click()
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r3:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_timeout(3000)
#page.wait_for_selector('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
page.wait_for_selector(ws_link_xpath)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1:
try:
page.get_by_role("button", name="View prompt").wait_for(state='visible', timeout=25000)
page.wait_for_selector('//*[@id="radix-:r8:"]/div/div[3]/div/div/div')
except Exception as e:
page.wait_for_selector('//*[@id="radix-:r7:"]/div/div[3]/div/div/div')
else:
page.wait_for_selector('//*[@id="radix-:r3:"]/div/div[3]/div/div/div')
else:
page.click('xpath=//*[@id="navigation"]/div/div/div/div[2]/div/div[2]/button/div/span[1]/img')
page.wait_for_selector('#icons_downloaded_counters')
except Exception as e:
ws_msg_erro = e.message
ws_erro = "Timeout 60000ms"
result_erro = ws_msg_erro.find(ws_erro)
if result_erro != -1:
page.reload()
page.get_by_role("button", name="avatar").click()
ws_nome_pagina_ia = page.url
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-photo')
#ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-premium')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-photo')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('fotos-gratis')
ws_link_xpath = '//*[@id="radix-:r6:"]/div/div[4]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('premium-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-vector')
ws_link_xpath = '//*[@id="radix-:r5:"]/div/div[3]/div/div/div'
if ws_count_link_premium == -1:
ws_count_link_premium = ws_nome_link_imagem.find('free-ai-image')
ws_link_xpath = '//*[@id="radix-:r7:"]/div/div[3]/div/div/div'
if ws_count_link_premium != -1:
#page.wait_for_timeout(3000)
#page.wait_for_selector('//*[@id="radix-:r6:"]/div/div[3]/div/div/div')
page.wait_for_selector(ws_link_xpath)
else:
ws_count_link_premium = ws_nome_pagina_ia.find('premium-ai-image')
if ws_count_link_premium != -1: