1

所以基本上思路就是用python登录一个网站,复制一个html页面的内容,只有登录后才能查看。(https下)

关于如何实现这一目标的任何建议?要求?http.client.HTTPSConnection?

我目前有

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)

非常感谢!

4

1 回答 1

2

你可以使用请求

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, ...}
于 2013-06-19T21:46:39.340 回答