Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Instagram Bot _ Posting Comments
#1
Hi Guys,

I have put together a basic bot that opens my instagram and comments on the first photo. I have managed to make it scroll down in random intervals but am not having much success in making it find and comment of additional photos. Any ideas on how to condense this code into a single action that repeats a number of times would help. Part of my code is below.

comment = "Awesome!"

driver.find_element_by_xpath("//textarea[@aria-label='Add a comment…']").click()

sleep(4)

driver.find_element_by_xpath("//textarea[@aria-label='Add a comment…']").send_keys(comment)

sleep(4)

driver.find_element_by_xpath("//button[contains(.,'Post')]").click()

sleep(4)

driver.execute_script("window.scrollTo(0, 2000);")

sleep(4)

driver.execute_script("window.scrollTo(0, 4000);")

sleep(4)

driver.execute_script("window.scrollTo(0, 6000);")

sleep(4)

print('Finished') 
Reply
#2
You can use instapy and that can make it all so much easy for you.Another approach can be using pyautogui.You can use it to locate the comment icon on the page and click it.
Reply
#3
Intapy API was discontinued.
Reply
#4
Tried to set up a for loop using selenium and the pyautogui.
If the code can not find ("//textarea[@aria-label='Add a comment…']") it crashes. If I # that line the scroll works fine.
I'll keep working on a solution. Any help would be great so that if the code can not find that line if loops back to the scroll.

for z in range(0,10):
    pyautogui.scroll(-1000)
    driver.find_element_by_xpath("//textarea[@aria-label='Add a comment…']")
    if True:
        driver.find_element_by_xpath("//textarea[@aria-label='Add a comment…']").click()
        driver.find_element_by_xpath("//textarea[@aria-label='Add a comment…']").send_keys(comment)
        driver.find_element_by_xpath("//button[contains(.,'Post')]").click()
    else:
        Print("nothing")
    time.sleep(2)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Instagram Stories Evil_Patrick 3 48,931 May-31-2022, 12:04 PM
Last Post: RosmenGelik
  Scroll Down Post Instagram Likes rmiguelantunes74 0 3,161 Oct-05-2020, 07:38 PM
Last Post: rmiguelantunes74
  Like ou Unlike Instagram rmiguelantunes74 3 2,553 Jun-14-2020, 08:50 AM
Last Post: rmiguelantunes74
  Instagram Phone Emulation kristianpython 0 2,013 May-19-2020, 11:54 AM
Last Post: kristianpython
  Error posting with requests julio2000 6 2,863 Mar-28-2020, 09:43 PM
Last Post: julio2000
  Posting value from excel to Form (Python+Selenium) revanth 0 1,799 Feb-05-2020, 10:44 AM
Last Post: revanth
  Posting html values to views/models in Django Malt 1 2,165 Sep-04-2019, 01:44 PM
Last Post: fishhook
  Post comments to Wordpress Blog SergeyLV 1 2,482 Aug-01-2019, 01:38 AM
Last Post: Larz60+
  Form add tree comments with mptt m0ntecr1st0 1 2,510 Feb-23-2019, 01:50 PM
Last Post: m0ntecr1st0
  BS4 Not Able To Find Text In CSS Comments digitalmatic7 4 5,235 Feb-27-2018, 03:45 AM
Last Post: digitalmatic7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020