简体   繁体   English

Instagram通过Selenium for Python登录

[英]Instagram login through Selenium for Python

I've been tinkering around with Selenium and PhantomJS since a few hours now. 从几个小时以来,我一直在研究Selenium和PhantomJS。 I'm trying to write a script that logs in to Instagram. 我正在尝试编写一个登录到Instagram的脚本。 That's it. 而已。 As simple as that. 就如此容易。

Here's what I've got so far : 这是到目前为止我得到的:

from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get('https://www.instagram.com/accounts/login')
username = driver.find_element_by_xpath('//*[@name="username"]')
password = driver.find_element_by_xpath('//*[@name="password"]')
login_btn = driver.find_element_by_xpath('//*[@class="_aj7mu _taytv _ki5uo _o0442"]')

username.send_keys("username")
password.send_keys("password!")

#test to see if input values are reflecting
print(username.get_attribute('value'))
print(password.get_attribute('value'))

#login
login_btn.click()
logged_in_class = driver.find_elements_by_class_name("logged-in")
not_logged_in_class = driver.find_elements_by_class_name("not-logged-in")

#to check if logged-in or not-logged-in
print(len(logged_in_class))
print(len(not_logged_in_class))


driver.quit()

The input values are reflecting correctly. 输入值正确反映。 There seems to be an issue with login. 登录似乎有问题。 Could anyone throw light on this topic. 任何人都可以阐明这个话题。

Thanks. 谢谢。

There is an SSL error on that site, you need to use these command-line options: 该网站上存在SSL错误,您需要使用以下命令行选项:

--ignore-ssl-errors=true --debug=true

You need to use onResourceError callback, to find out, what's going wrong. 您需要使用onResourceError回调来找出问题所在。

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

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