foo = ['hello', 'hi', 'sup', 'hey', 'yo']
def main():
actions = ActionChains(driver)
with open('links.txt', 'r') as f:
urls = []
for url in f:
rand = random.choice(foo)
driver.get(url)
time.sleep(3)
driver.execute_script("window.scrollTo(0, 200)")
time.sleep(1)
try:
driver.find_element_by_class_name('comment-simplebox-renderer-collapsed-content').click()
actions.send_keys(rand)
actions.perform()
driver.find_element_by_xpath("""//*[@id="comment-simplebox"]/div[3]/div[2]/button[2]""").click()
time.sleep(3)
except NoSuchElementException:
pass
Instead of picking a random string I have in the foo list, it instead picks a random string the first time, the second time it just picks the first string and adds another random string to that. So it just adds strings to the rand variable instead of overwriting it. How can I solve this?
I tried moving up the rand variable but that didn't work.
Aucun commentaire:
Enregistrer un commentaire