Login to instagram using python

17,086

you can get idea to implement this from here

Logging to Instagram using Python requests

my code for login to instagram

import pdb
from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get('https://www.instagram.com/accounts/login/')
dom = driver.find_element_by_xpath('//*')

pdb.set_trace()
username = dom.find_element_by_name('username')
password = dom.find_element_by_name('password')
login_button = dom.find_element_by_xpath('//*[@class="_qv64e _gexxb _4tgw8 _njrw0"]')

username.clear()
password.clear()
username.send_keys('your username')
password.send_keys('your password')

login_button.click()
driver.get('https://www.instagram.com/accounts/login')

if 'logged-in' in driver.page_source:
    print 'Logged in'
Share:
17,086
Admin
Author by

Admin

Updated on June 13, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to login to instagram.Here is my code

    from bs4 import BeautifulSoup
    from requests import *
    payload = {
        'action': 'login',
        'username': 'name',
        'password': 'pass'
    }
    
    with session() as c:
        c.post('https://www.instagram.com/login.php', data=payload)
        response = c.get('https://www.instagram.com/accounts/edit/')
        print(response.headers)
        print(response.text)
    

    unfortunately it doesn't seem to log me in. I get:

    lt-ie8 lt-ie7 not-logged-in client-root
    

    Any solutions would be much appreciated. Thanks.