-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
70 lines (53 loc) · 2.26 KB
/
bot.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
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
NumeSite = "www.pbinfo.ro"
sleepTimeDuration = 1.5
NrOfProblem = 0
def LogIn(driver, username, pasword) :
driver.find_element_by_id("user").send_keys(username)
driver.find_element_by_id("parola").send_keys(pasword)
driver.find_element_by_xpath("//*[@id=\"form-login\"]/div/div[2]/div[4]/button").click()
time.sleep(3)
def isproblem(driver) :
if driver.title == NumeSite :
return 0
else :
return 1
def writeProblem(driver) :
message = driver.find_element_by_xpath("//*[@id=\"form-incarcare-solutie\"]/div[2]/div/div[6]/div[1]/div/div/div/div[5]/div/pre")
message.send_keys(Keys.SHIFT, Keys.INSERT)
driver.find_element_by_xpath("//*[@id=\"btn-submit\"]").click()
time.sleep(3)
def CopyProblem(driver) :
SolvedProblem = driver.find_element_by_xpath("//*[@id=\"zona-mijloc\"]/div/div[10]/div[2]/pre")
SolvedProblem.click()
SolvedProblem.send_keys(Keys.CONTROL, 'a')
time.sleep(1)
SolvedProblem.send_keys(Keys.CONTROL, 'c')
driverChrome = webdriver.Chrome(executable_path=r"C:\Users\jmogo\AppData\Local\Temp\Temp1_chromedriver_win32.zip\chromedriver.exe")
driverChrome.get("https://www.pbinfo.ro/")
LogIn(driverChrome, "test", "test")
driverFirefox = webdriver.Firefox(executable_path=r"C:\Users\jmogo\AppData\Local\Temp\Temp1_geckodriver-v0.28.0-win64.zip\geckodriver.exe")
driverFirefox.get("https://www.pbinfo.ro/")
LogIn(driverFirefox, "test1", "test1")
for x in range (0, 4000) :
time.sleep(sleepTimeDuration)
NrOfProblem += 1
NewUrl = "https://www.pbinfo.ro/probleme/" + str(NrOfProblem)
UrlSolOF = "https://www.pbinfo.ro/?pagina=solutie-oficiala&id=" + str(NrOfProblem)
driverChrome.get(NewUrl)
driverFirefox.get(NewUrl)
#Chrome cont gol
#firefox cont test
if isproblem(driverChrome) == 1 :
driverChrome.get(UrlSolOF)
driverFirefox.get(UrlSolOF)
time.sleep(1.5)
if "numai de utilizatorii" in driverChrome.page_source:
if "numai de utilizatorii" in driverFirefox.page_source:
driverChrome.title
else :
CopyProblem(driverFirefox)
driverChrome.get(NewUrl)
writeProblem(driverChrome)