1

So basically the idea is to use python to login to a website and copy the content of a html page that can only be viewed after you have logged in. (under https)

Any suggestions on how to achieve this? Requests? http.client.HTTPSConnection?

I currently have

h1 = http.client.HTTPSConnection(URL)  #question: what exactly should this url page be?
                                  https://accounts.google.com/ServiceLoginhl=en&continue=https://www.google.ca/
                                   or https://google.ca
userAndPass = b64encode(b"usrname:pwd").decode("ascii")
headers = { 'Authorization' : 'Basic %s' %  userAndPass }
#then connect
h1.request('GET', '$THEPAGETHATIWANTTOACCESS', headers=headers)

Thanks a lot!

1
  • I've had much better success using Mechanize or requests than httplib. Commented Jun 19, 2013 at 21:46

1 Answer 1

2

you can use requests

r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'private_gists': 419, u'total_private_repos': 77, ...}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.