T
T
Timebird2018-12-03 01:44:03
Python
Timebird, 2018-12-03 01:44:03

How to parse Instagram post text by username?

You need to parse the text of Instagram posts. At the moment, I have implemented using this video to enter through the login password and follow the link to the desired username, but I don’t understand how to proceed. How can I get the text of all posts from the page and is it possible at all? I am attaching the code.
Thank you very much in advance!

from selenium import webdriver   
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


username = USERNAME
password = PASSWORD



class InstagramBot:
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.driver = webdriver.Firefox()

    def classBrowser(self):
        self.driver.close()


    def login(self):

        driver = self.driver
        driver.get("https://www.instagram.com")
        time.sleep(2)

        login_button = driver.find_element_by_xpath("//a[@href='/accounts/login/?source=auth_switcher']")
        login_button.click()
        time.sleep(2)

        user_name_elem = driver.find_element_by_xpath("//input[@name='username']")
        user_name_elem.clear()
        user_name_elem.send_keys(self.username)

        password_elem = driver.find_element_by_xpath("//input[@name='password']")
        password_elem.clear()
        password_elem.send_keys(self.password)
        password_elem.send_keys(Keys.RETURN)
        time.sleep(2)


    def get_posts(self, hashtag):
        driver = self.driver
        driver.get("https://www.instagram.com/" + hashtag + "/")
        time.sleep(2)


andreyIG = InstagramBot(username, password)
andreyIG.login()
andreyIG.get_posts('cats_of_instagram')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semchenko, 2018-12-03
@0xcffaedfe

api tried to use, and not fence the garden?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question