简体   繁体   English

使用python登录Instagram

[英]Login to instagram using python

I am trying to login to instagram.Here is my code我正在尝试登录 instagram。这是我的代码

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.谢谢。

you can get idea to implement this from here你可以从这里得到想法来实现这个

Logging to Instagram using Python requests 使用 Python 请求登录 Instagram

my code for login to instagram我登录 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'

您需要一个 API 密钥才能调用 Instagram API,而且我认为您不能直接登录这样的人。

我建议您使用SeleniumPhantomJS webdriver

Thanks all for the help. 谢谢大家的帮助。 I decided to use selenium insinstead 我决定用硒代替

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM