Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.common.exceptions import TimeoutException
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.webdriver.common.by import By
  6. import time
  7.  
  8. driver = webdriver.Chrome('/Users/Martin/Desktop/chromedriver')
  9. timeout = 30
  10. driver.get("https://onevideo.aol.com/#/")
  11.  
  12.  
  13. def main():
  14. login()
  15. clone()
  16. Name()
  17. Rate()
  18. Floor()
  19. Download()
  20.  
  21.  
  22. class login():
  23. try:
  24. element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "input.ng-valid:nth-child(1)"))
  25. WebDriverWait(driver, timeout).until(element_present)
  26. except TimeoutException:
  27. print ("Timed out waiting for page to load")
  28.  
  29. username = driver.find_element_by_css_selector("input.ng-valid:nth-child(1)")
  30. username.send_keys("martinbouhier")
  31. driver.find_element_by_css_selector("button.btn:nth-child(2)").click()
  32. try:
  33. element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.group-field-block:nth-child(2) > input:nth-child(2)"))
  34. WebDriverWait(driver, timeout).until(element_present)
  35. except TimeoutException:
  36. print ("Timed out waiting for page to load")
  37.  
  38. password = driver.find_element_by_css_selector("div.group-field-block:nth-child(2) > input:nth-child(2)")
  39. password.send_keys("pass")
  40. driver.find_element_by_css_selector(".button").click()
  41. element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1.ng-scope > span:nth-child(1)')))
  42.  
  43.  
  44. class clone():
  45. #Clonar
  46. url = driver.get("https://onevideo.aol.com/#/inventorysources")
  47. try:
  48. element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.ngRow:nth-child(1) > div:nth-child(1) > div:nth-child(9) > div:nth-child(1) > div:nth-child(1) > adap-options-menu:nth-child(1) > div:nth-child(1) > button:nth-child(2)"))
  49. WebDriverWait(driver, timeout).until(element_present)
  50.  
  51. except TimeoutException:
  52. print ("Timed out waiting for page to load")
  53. driver.find_element_by_css_selector('div.ngRow:nth-child(1) > div:nth-child(1) > div:nth-child(9) > div:nth-child(1) > div:nth-child(1) > adap-options-menu:nth-child(1) > div:nth-child(1) > button:nth-child(2)').click()
  54. try:
  55. element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.ngRow:nth-child(1) > div:nth-child(1) > div:nth-child(9) > div:nth-child(1) > div:nth-child(1) > adap-options-menu:nth-child(1) > div:nth-child(1) > button:nth-child(2)"))
  56. WebDriverWait(driver, timeout).until(element_present)
  57.  
  58. except TimeoutException:
  59. print ("Timed out waiting for page to load")
  60. driver.find_element_by_css_selector('.open > ul:nth-child(5) > li:nth-child(3) > a:nth-child(1)').click()
  61.  
  62. def run(d):
  63. NewTag("url")
  64. Device = str(d.get("Li_platform")) #Mobile Web
  65. Inicio_Li_Platform = ('//*[@id="platform_listbox"]/li[')
  66. Final_Li_Platform = (']')
  67. Platform(Inicio_Li_Platform+""+Device+""+Final_Li_Platform)
  68. NameTag(d.get("TagName"))
  69. Floor_Rate(d.get("Floor_price"))
  70. Save_Tag('save')
  71. Inicio_Li_Publisher = ('//*[@id="publisher_listbox"]/li[')
  72. Final_Li_Publisher = (']')
  73. Publisher = str(d.get("Li_Publisher")) #Publisher Altitude
  74. Publisher_Li(Inicio_Li_Publisher+""+Publisher+""+Final_Li_Publisher)
  75. Tag_Rate_and_Save(d.get("Tag_Rate"))
  76. time.sleep(2)
  77.  
  78.  
  79. def main():
  80. login("martin", "pass")
  81. tags = (nametags)
  82.  
  83. for tag in (tag.strip() for tag in tags.split(",")):
  84. d = (Inventory_data.get("Inventario_datos")).get(tag, None)
  85. if d:
  86. run(d)
  87. else:
  88. print('Error: Clave "{}" no encontrada.'.format(tag))
  89. driver.close()
  90.  
  91.  
  92. def login(email, passwd):
  93. url = "url/login/"
  94. email_find = '//*[@id="form_username"]'
  95. passwd_find = '//*[@id="form_password"]'
  96. boton_find = '//*[@id="login_submit"]'
  97. driver.get(url)
  98. user = driver.find_element_by_xpath(email_find)
  99. user.send_keys(email)
  100. password = driver.find_element_by_xpath(passwd_find)
  101. password.send_keys(passwd)
  102. boton_find = driver.find_element_by_xpath(boton_find).click()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement