35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
from instapy import InstaPy
|
||
|
import time
|
||
|
|
||
|
un = "elsewhereelsie"
|
||
|
pw = "DE!k6wKV"
|
||
|
|
||
|
# Initialize InstaPy session
|
||
|
session = InstaPy(username=un, password=pw)
|
||
|
session.login()
|
||
|
|
||
|
# Navigate to the specific Instagram post
|
||
|
post_url = 'https://www.instagram.com/p/C3w29yMO0UN/'
|
||
|
session.browser.get(post_url)
|
||
|
|
||
|
# Ensure the page is loaded properly before finding elements
|
||
|
time.sleep(5) # Adjust this sleep time based on your internet speed
|
||
|
|
||
|
# XPath for the comment textarea
|
||
|
comment_textarea_xpath = '/html/body/div[8]/div[1]/div/div[3]/div/div/div/div/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/div/textarea'
|
||
|
|
||
|
# XPath for the submit button
|
||
|
submit_button_xpath = '/html/body/div[8]/div[1]/div/div[3]/div/div/div/div/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/div/div[2]/div'
|
||
|
|
||
|
# Find the comment box using the XPath and enter the comment
|
||
|
comment_box = session.browser.find_element_by_xpath(comment_textarea_xpath)
|
||
|
comment_box.click()
|
||
|
comment_box.send_keys('Love this!')
|
||
|
|
||
|
# Find the submit button using the XPath and click it to post the comment
|
||
|
submit_button = session.browser.find_element_by_xpath(submit_button_xpath)
|
||
|
submit_button.click()
|
||
|
|
||
|
# Clean up
|
||
|
session.end()
|