Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging to Instagram using Python requests

I am trying to write a script in python, to log into http://insta.friendorfollow.com/ and get the list of the people that are not following back. I want to use "requests module", so far I made numerous attempts with no luck. My code is as follow :

import requests, re

f = open('file', 'w')
r = requests.get('http://insta.friendorfollow.com/')
next_url = re.findall(ur'<a href=\"(.*)\" type=\"submit\"', r.content)

r = requests.get(next_url[0])

action = re.findall(ur'action=\"(.*)\"', r.content)
csrfmiddlewaretoken = re.findall(ur'name=\"csrfmiddlewaretoken\" value=\"(.*)\"', r.content)

print action
print csrfmiddlewaretoken

payload = {
'csrfmiddlewaretoken': csrfmiddlewaretoken[0],
'username': 'SOMEUSER',
'password':'SOMEPASS'
}

g = requests.post("https://instagram.com/"+action[0],
  data=payload, allow_redirects=True)


print >> f, g.text

Can some one tell me what I am doing wrong? and what would it be the right way to do it. A script would be much appreciated.

like image 585
mahmoh Avatar asked Apr 08 '14 15:04

mahmoh


People also ask

How do I log into Instagram with Python requests?

Getting {"user":false,"authenticated":false,"status":"ok" MY CODE: import re import requests from datetime import datetime link = 'https://www.instagram.com/accounts/login/' login_url = 'https://www.instagram.com/accounts/login/ajax/' time =

Is there an Instagram API for Python?

You can now schedule your instagram posts programmatically without relying on limiting and expensive apps like Hootsuite and Later. You can create your own code to post to instagram up to 25 posts a day using the Instagram Graph API.

How is Instagram using Python?

To help the scaling and efficiency, engineers at Instagram have created static sort checkers using Python and Pyre, which Instagram uses to investigate its servers. That is the reason Instagram engineers have created and used many modules for Python and used Python's beyond-the-border capabilities.


1 Answers

All is fine now,

#!/usr/bin/env python

username = "username"
password = "password"

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re

driver = webdriver.PhantomJS()
driver.get("http://insta.friendorfollow.com")
driver.find_elements_by_tag_name("a")[1].click()

print "Perimene file....".upper()
driver.find_element_by_name('username').send_keys(username)
driver.find_element_by_name('password').send_keys(password)
driver.find_element_by_class_name("button-green").click()

try:
  driver.find_elements_by_name("allow")[1].click()
except:
  pass

f = open(username+".txt", 'w')
malakes = re.findall(ur'data-id=\"([0-9]*)\"', driver.page_source)[::-1]
for malakas in malakes:
  print >> f, malakas

f.close()
driver.quit()
like image 174
mahmoh Avatar answered Oct 26 '22 01:10

mahmoh