I'm using selenium to iterate through the different combinations of a variable's parameters and download the data from a website. However, the for loop function stops working when there's no data; I also notice when selenium stops the webpage contains a text labeled "Cannot produce results.". Thus, I figured to use an if statement with selenium to search for "Cannot produce results" and skip to the next loop if the aforementioned text were found. An example would be something like this:
for i in loop:
# Select variable
driver.find_element_by_css_selector("...").click()
# Select first parameter
driver.find_element_by_css_selector("...").click()
# Select second parameter
driver.find_element_by_css_selector("...").click()
data_check = driver.find_elements_by_partial_link_text('Cannot produce results.')
if data_check[0].is_displayed():
continue
# Download data
# Close driver, continue with next iteration
However, this code simply stops the function at continue, doesn't complete the download portion of the code, and iterates through the rest of the loop. Any idea with how to solve this? Also, please let me know if the question is confusing.
Aucun commentaire:
Enregistrer un commentaire