Log in with Python

I try to log in to http://www.qualtrics.com/login/ and then save the cookie, but it will not work.

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
opener.addheaders =[('Referer', 'http://www.qualtrics.com'),
('User-Agent','Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0'),
                        ('Content-Type','application/x-www-form-urlencoded')]
url = 'http://www.qualtrics.com/login/'
data = {'method' : '1', 'login' : 'my-username', 'password' : 'my-password'}
req = urllib2.Request(url, urllib.urlencode(data))
res = opener.open(req)

But the answer is what someone without an account will see (it doesn't work). Any help? In addition, the cookie should look like this:

# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
value / value / value etc
+4
source share
2 answers

As long as it looks a little wider, selenium will not provide you with a good base to start. There are many good examples. Theft from this example

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.example.com')
browser.find_element_by_name('username').send_keys('myusername')
browser.find_element_by_name('password').send_keys('mypassword')
browser.find_element_by_class_name('welcomeLoginButton').click()
cookies = browser.get_cookies()

You may need to add a few pending statements, but there are many examples here on stack overflows and a lot of information in documents

EDIT: ​​ .

  • find_element_by_ .
  • cookie . cookie - {name: value}
+4

mechanize. , .

- :

import mechanize

browser = mechanize.Browser()
browser.open("http://www.example.com")
browser.select_form(name="myform")
browser["username"] = "username"
browser["password"] = "password"
browser.submit()

cookie ( ). , (referrer, user-agent ..).

: http://wwwsearch.sourceforge.net/mechanize/

EDIT: (, ) , / .

+2

Source: https://habr.com/ru/post/1544080/


All Articles