דוגמה לתכנית שטוענת כרטיס רב קו באופן אוטומטי
תכנית זו טוענת 30 ש"ח לכרטיס המחובר למחשב.
היא מצפה לקובץ עם פרטי המשתמש בשם rk.conf
היא עובדת בלינוקס ומשתמשת בפיירפוקס.
בווינדוס זה עלול להיות קצת יותר מסובך (כמו כל דבר). ההתקנה של אפליקצית רב קו בלינוקס היא מערכתית, בעוד שבווינדוס היא ספציפית לבראוזר, אבל selenium משתמש בפרופיל נקי, לכן אני חושש שיהיה צורך לקנפג אותו יותר כדי שיצליח להתחבר לקורא הכרטיסים.
סביר להניח שאפשר להשתמש בכרום, או בברואזרים אחרים ש-selenium תומך בהם.
קוד:
#!/usr/bin/python3
import sys,os,time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import configparser
config = configparser.ConfigParser()
config.read("rk.conf")
fp = webdriver.FirefoxProfile()
fp.set_preference("network.protocol-handler.app.ravkav", "/usr/bin/ravkavonline")
fp.set_preference("network.protocol-handler.external.ravkav", True)
handlers=os.path.join(fp.path,"handlers.json")
open(handlers,"w").write('{"defaultHandlersVersion":{"en-US":4},"schemes":{"ravkav":{"action":4}}}')
options = Options()
#options.headless = True
driver = webdriver.Firefox(options=options, firefox_profile = fp)
driver.get("[URL]https://ravkavonline.co.il/he/store/login[/URL]")
username=driver.find_element_by_id('id_email')
password=driver.find_element_by_id('id_password')
button=driver.find_element_by_xpath('//button[text()="התחברות"]')
username.send_keys(config['main']['username'])
password.send_keys(config['main']['password'])
button.click()
driver.implicitly_wait(3)
time.sleep(1)
button=driver.find_element_by_xpath('//a[text()="סרוק כרטיס"]')
button.click()
driver.implicitly_wait(3)
time.sleep(3)
button=driver.find_element_by_xpath('//a[text()="חוזי נסיעה"]')
button.click()
time.sleep(1)
button=driver.find_element_by_xpath('//span[text()="30₪"]')
button.click()
time.sleep(1)
button=driver.find_element_by_xpath('//button[contains(.,"לרכישה")]')
button.click()
id_i=driver.find_element_by_id('id_personalId')
id_i.send_keys(config['main']['id'])
time.sleep(1)
button=driver.find_element_by_xpath('//button[text()="לתשלום"]')
button.click()
sleep(5)
if driver.title=='הכרטיס נטען בהצלחה':
print("הצלחה")
else:
print("כשלון")
sys.exit(1)