Use dict.iteritems
, first use the key to create the url, then iterate over the tags of that url and thus for each dictionary key:
Lista = {'829690' :['testmartin','--test$2--'],
'1016244':['camionetas','autos']}
for id, tags in Lista.iteritems():
url = driver.get("https://onevideo.aol.com/#/marketplaceconnection/{}".format(id.strip()))
# Codigo a ejecutar antes de pasar los tags
for tag in tags:
nombre.send_keys(tag)
If I understand you, you should do something like this:
def Target():
for id, tags in Lista.iteritems():
url = driver.get("https://onevideo.aol.com/#/marketplaceconnection/{}".format(id.strip()))
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar-inhiner > ul:nth-child(1) > li:nth-child(4) > a:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('.navbar-inhiner > ul:nth-child(1) > li:nth-child(4) > a:nth-child(1)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "li.ng-scope:nth-child(6) > a:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('li.ng-scope:nth-child(6) > a:nth-child(1)').click()
#Cargado de tags
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "span.ng-scope:nth-child(12) > div:nth-child(1) > span:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('span.ng-scope:nth-child(12) > div:nth-child(1) > span:nth-child(1)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "#s2id_autogen30"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
nombre = driver.find_element_by_css_selector('#s2id_autogen30')
for tag in tags:
nombre.send_keys(tag)
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, '.select2-results-dept-0'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
nombre2 = driver.find_element_by_css_selector('.select2-results-dept-0').click()
driver.find_element_by_css_selector('button.btn-success:nth-child(3)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.modal-footer:nth-child(3) > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('div.modal-footer:nth-child(3) > button:nth-child(1)').click()
#Guardado de la connection
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, ".bs-docs-social-buttons > li:nth-child(2) > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector(".bs-docs-social-buttons > li:nth-child(2) > button:nth-child(1)").click()
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "adap-marketplace-connections-grid-filter.ng-scope > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
Not being able to access the website, I do not know if everything is indented where it should be, but the idea should be this one.
You should not use classes, your application follows a structured paradigm, not object-oriented programming. It does not make sense to create an object that is not really such, just execute code. Use functions ( def
) and call them in the main
as you do with the classes.