ウェブサイトからデータをプログラマチックに収集するのに荒い時間があります。私はthis exampleを使ってサーバにログインしようとしていますが、これは間違ったタイプのログインだと思っているので動作しません。Python内のログインページにリダイレクトするページを取得する
htmlを解析するためにデータをダウンロードしようとすると、アクセスしようとしているサイトがログインページにリダイレクトされます。
これはURLである:
https://mtred.com/rewards.html
と相続コード:私は報酬を開こうとすると
# build opener with HTTPCookieProcessor
o = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(o)
# assuming the site expects 'user' and 'pass' as query params
p = urllib.urlencode({ 'UserLogin_username': 'mylogin', 'UserLogin_password': 'mypass' })
# perform login with params
f = o.open('http://www.mtred.com/user/login.html', p)
data = f.read()
f.close()
# second request should automatically pass back any
# cookies received during login... thanks to the HTTPCookieProcessor
f = o.open('https://www.mtred.com/rewards.html',p)
data = f.read()
print data
それが再びログインページに私を蹴ります。この情報は公開APIで利用できないため、報酬を自動的に渡すようにしています