用python登录-megaupload [英] Login with python - megaupload
问题描述
我正在尝试修复一个程序,该程序可以登录到我的MU帐户并检索一些数据....
I'm trying to fix a program which can login to my MU account and retrieve some data....
我不知道我在做什么错....这就是代码:
I don't know what am I doing wrong....That's the code:
#!/usr/bin/env python
import urllib, urllib2, cookielib
username = 'username'
password = 'password'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username' : username, 'password' : password})
opener.open('http://megaupload.com/index.php?c=login', login_data)
resp = opener.open('http://www.megaupload.com/index.php?c=filemanager')
print resp.read()
谢谢!
推荐答案
好吧,我只是自己实现了它,看来您只是忘记了一个值-这就是为什么我总是使用TamperData或类似的方法来检查浏览器发送到的内容服务器-比通过HTML更轻松,更短.
Okay I just implemented it myself and it seems you just forgot one value - that's why I always use TamperData or something similar to just check what my browser is sending to the server - WAY easier and shorter than going through the HTML.
无论如何,只要在字典中添加'redir':1就可以了:
Anyways just add 'redir' : 1 to your dict and it'll work:
import http.cookiejar
import urllib
if __name__ == '__main__':
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
login_data = urllib.parse.urlencode({'username' : username, 'password' : password, 'login' : 1, 'redir' : 1})
response = opener.open("http://www.megaupload.com/?c=login", login_data)
with open("test.txt", "w") as file:
file.write(response.read().decode("UTF-8")) #so we can compare resulting html easily
尽管我必须说我现在要看一下机械化和合作-我经常做这样的事情,所以这很值得.尽管我不能强调,最重要的帮助仍然是浏览器插件,它可以让您检查已发送的数据;)
Although I must say I'll have a look at mechanize and co now - I do something like that often enough that it could be quite worthwhile. Although I can't stress enough that the most important help is still a browser plugin that lets you check the sent data ;)
这篇关于用python登录-megaupload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!