Python - Reading web page after authentication
Question: First, sorry for my english, it's not my mother tongue. Anyway, some grammar
errors will not kill you :) Hopefully.

I'm not able to get some information from a web page due to authentication
system.

The website is : www.matchendirect.fr It's a French site and there is no way
to turn it into english (sorry for the inconvenience) This website displays
football game information.

My purpose is to get forecast data (displayed in the middle of the page, there
is a table with forecast displayed called "Pronostics des internautes" but the
content of this table is displayed only if you're logged in)

Here is my code :

    
    
    import urllib2, cookielib
    cookieJar = cookielib.CookieJar()
    auth_url="http://www.matchendirect.fr/cgi/ajax/authentification.php?f_contexte=auth_form_action&f_email=pkwpa&f_mot_de_passe=pkw_pa"
    url="http://www.matchendirect.fr/live-score/colombie-bresil.html"
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
    request = urllib2.Request(auth_url)
    response = opener.open(request)
    response = opener.open(url)
    webpage=response.read()
    

To be sure to be log in, we can try this:

    
    
    if webpage.find("prono_stat_data")!=-1:
        print("I'm logged in")
    

I think my cookies managment isn't good...

Here are my credentials, play with them, it's obviously a fake account create
only for this topic.

username : pkwpa password : pkw_pa

Hope someone could help me.


Answer: here is what you're looking for : <http://docs.python-
requests.org/en/latest/user/install/#install> Use it like below: from requests
import session

    
    
    with session() as c:
        c.get('http://www.matchendirect.fr/cgi/ajax/authentification.php?f_contexte=auth_form_action&f_email=pkwpa&f_mot_de_passe=pkw_pa')
        request = c.get('http://www.matchendirect.fr/live-score/colombie-bresil.html')
        print request.headers
        print request.text
    

Cheers

