mardi 30 juin 2020

List is accepting only one comment

I was passing customizable comments for Instagram. I was writing the following Code:

def comment(username,comment) :
    driver.get(f"https://www.instagram.com/{username}/")
    time.sleep(5)

    for i in range(7):
        driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")

    href_found = driver.find_elements_by_tag_name("a")
    pic_href = [ele.get_attribute('href') for ele in href_found if '.com/p' in ele.get_attribute('href')]

    #comment = ["Nice Work"]

    for ele in pic_href:
        driver.get(ele)
        time.sleep(3)


        driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")

        commentbox = lambda: driver.find_element_by_xpath("/html/body/div[1]/section/main/div/div[1]/article/div[2]/section[3]/div/form/textarea")
        commentbox().click()
        commentbox().clear()


        for i in comment:
            commentbox().send_keys(i)
            time.sleep(random.randint(1,7)/30)

        commentbox().send_keys(Keys.ENTER)


if __name__ == "__main__":
    login("<id>","<password>")
    desire_user = input("Enter Instagram Username to Comment: ")
    comm = [x for x in input("Enter comments").split(",")]
    for i in comm:
        comment(desire_user,i)

The idea is to create a list of comments and enter one comment per post. For example: passing the first comment for the first post and then next comment for the next post and so on.

Can anyone please help me with the following script.




Aucun commentaire:

Enregistrer un commentaire