Python: Logging into website with python using GET request
Question: I'm using python 3.4.3 and I'm trying to login to OKCupid using requests.

The page that my code returns is the initial login page, not the page a user
would see after successfully logging in. I have tried looking at several
answers on here and other tutorials and most of them direct me to inspect the
developer tab and look at requests with method "POST", but I do not see any
such requests.

Instead, I see "GET" requests and I'm unsure how requests handle those. I have
tried a number of different approaches, but none worked. Here is the simpler
code I have:

    
    
    import requests
    from bs4 import BeautifulSoup
    
    user='USERNAME'
    pw='PASSWORD'
    url='http://www.okcupid.com/login'
    
    session=requests.session()
    
    values = {'login_username':user, 'login_password':pw}
    r = session.post(url,data=values)
    soup = BeautifulSoup(r.content)
    pSoup = BeautifulSoup.prettify(soup)
    
    print(soup.title.string)
    


Answer: I was able to figure it out. In case this is helpful to someone in the future:
there were two things preventing my previous code from working:

  1. I needed to specify 'https' instead of 'http' in the url.
  2. I was missing a the 'okc_api' value in the values vector. I hadn't detected this previously because Chrome's Developer tools did not have "Preserve log" checked. As a result, Chrome was erasing the login "POST" request before I could look at the "Form Data" Values. 

Here is the revised code:

    
    
    import requests
    from bs4 import BeautifulSoup
    
    user='USERNAME'
    pw='PASSWORD'
    url='https://www.okcupid.com/login'
    
    session=requests.session()
    
    values = {'username': user, 'password': pw, 'okc_api': '1'}
    session.post(url, data=values)
    page = session.get('http://www.okcupid.com/')
    
    soup = BeautifulSoup(page.content)
    print(soup.title.string)
    
    session.close()
    

