我正在尝试使用argparse通过python脚本登录我的Instagram。它似乎连接,但它打印出“此页面无法加载。如果您在浏览器中禁用了cookie,或者您正在私人模式下浏览,请尝试启用cookie或关闭私人模式,然后重试您的操作” 这是我的代码:
import argparse
import mechanicalsoup
from bs4 import BeautifulSoup
parser = argparse.ArgumentParser(description='Login to Instagram.')
parser.add_argument("username")
parser.add_argument("password")
args = parser.parse_args()
browser = mechanicalsoup.Browser()
login_page = browser.get("https://instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/?client_id=9d836570317f4c18bca0db6d2ac38e29%26redirect_uri=http://websta.me/%26response_type=code%26scope=comments%2Brelationships%2Blikes")
# we grab the login form
login_form = login_page.soup.select(".dialog-main")[0].select("#login-form")[0]
# specify username and password
login_form.select("#id_username")[0]['value'] = args.username
login_form.select("#id_password")[0]['value'] = args.password
#submit
page2 = browser.submit(login_form, login_page.url)
#verify login
p = page2.soup.p.string
print(p)
print(args.password)
答案 0 :(得分:1)
library可以从instagram访问python。要登录,您需要以下代码:
from instagram.client import InstagramAPI
access_token = "YOUR_ACCESS_TOKEN" # get this from instagram
client_secret = "YOUR_CLIENT_SECRET" # this, too, from instagram
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print media.caption.text
换句话说,不要重新发明轮子。
答案 1 :(得分:0)
请参阅此答案,您现在还需要包含客户端密码以使用该库登录API。
Debugging Python Instagram API client - 'NoneType' has no len()