Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Selenium for Python登录Instagram_Python_Selenium Webdriver_Phantomjs - Fatal编程技术网

通过Selenium for Python登录Instagram

通过Selenium for Python登录Instagram,python,selenium-webdriver,phantomjs,Python,Selenium Webdriver,Phantomjs,几个小时以来,我一直在修补硒和幻影。我正在尝试编写一个登录Instagram的脚本。就这样。就这么简单 以下是到目前为止我得到的信息: from selenium import webdriver driver = webdriver.PhantomJS() driver.get('https://www.instagram.com/accounts/login') username = driver.find_element_by_xpath('//*[@name="username"]')

几个小时以来,我一直在修补硒和幻影。我正在尝试编写一个登录Instagram的脚本。就这样。就这么简单

以下是到目前为止我得到的信息:

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()
输入值反映正确。登录似乎有问题。有人能解释一下这个话题吗


谢谢。

该站点上存在SSL错误,您需要使用以下命令行选项:

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

您需要使用callback来找出问题所在。

尝试使用Chrome作为webdriver。PhantomJS基于Qt,与现代网站不完全兼容。我实际上通过Chrome webdriver调试了这个问题,因为我可以看到发生了什么。有了幻影,我什么都看不见。结果表明,代码运行良好。