Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- import json, os
- def alobgUpdate(driver, username_entry, password_entry):
- #load alo.bg login form
- driver.get("https://www.alo.bg/login.php")
- #find the input boxes
- username_input = driver.find_element_by_name("username")
- password_input = driver.find_element_by_name("password")
- #input the user data and login
- username_input.clear()
- username_input.send_keys(username_entry)
- password_input.clear()
- password_input.send_keys(password_entry)
- submit = driver.find_element_by_xpath('//button[@type="submit"]')
- submit.click()
- #load the page that lists the ads
- driver.get('http://www.alo.bg/user_online_ads.php')
- #get the links for updating all of the ads and click them
- updates = driver.find_elements_by_link_text('Направи първа безплатна')
- for update in updates:
- update.click()
- try:
- alert = driver.switch_to_alert()
- alert.accept()
- print("The ad was update successfully")
- except:
- print("The current ad was already updated today")
- def bazarUpdate(driver, email_entry, password_entry):
- #load the bazar.bg login form
- driver.get("https://bazar.bg/user/login")
- #get the input boxes
- email_input = driver.find_element_by_id("mail")
- password_input = driver.find_element_by_id("password")
- #input the user data and login
- email_input.clear()
- email_input.send_keys(email_entry)
- password_input.clear()
- password_input.send_keys(password_entry)
- submit = driver.find_element_by_name("submitBtn")
- submit.click()
- #get the links for updating all of the ads and click them
- updates = driver.find_elements_by_link_text('ОБНОВИ')
- for update in updates:
- try:
- update.click()
- driver.implicitly_wait(1)
- try:
- close_button = driver.find_element_by_xpath('//*[@title="close"]')
- close_button.click()
- print ("The current ad was already updated today")
- except:
- print ("The current ad was update successfully")
- except:
- print ("Shit happened")
- if __name__ == '__main__':
- #Get config file path
- config_path = os.path.join(os.path.dirname(__file__), 'config.json')
- #Read the user data
- with open(config_path, 'r') as f:
- config = json.load(f)
- username = config['data']['username']
- password = config['data']['password']
- email = config['data']['email']
- #Create an instance of the chrome browser
- driver = webdriver.Chrome()
- #Update the alo.bg ads
- alobgUpdate(driver, username, password)
- #Update the bazar.bg ads
- bazarUpdate(driver, email, password)
- #Close the browser
- driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement