I want to login to Ideone.com using python script and then extract stuff from my own account using subsequent requests using python script. This is what I used for logging in to the website:
import requests
import urllib
from bs4 import BeautifulSoup
url='http://ideone.com/account/login/'
body = {'username':'USERNAME', 'password':'PASSWORD'}
s = requests.Session()
loginPage = s.get(url)
soup = BeautifulSoup(loginPage.text)
r = s.post(soup.form['action'], data = body)
print r
This code successfully logs me in to my ideone account. But if I make subsequent call(using BeautifulSoup) to access my account details, it send me HTML of login page again.
How can I save session for a particular script so that it accepts the subsequent calls? Thanks in advance and sorry if this has been asked earlier.
Here is how we can do this:
from requests import session
from bs4 import BeautifulSoup
payload = {
'action' : 'login',
'username' : 'USERNAME',
'password' : 'PASSWORD'
}
login_url='http://ideone.com/account/login/'
with session() as c:
c.post(login_url, data = payload)
request = c.get('http://ideone.com/myrecent')
print request.headers
print request.text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With