使用机械化登录megaupload [英] Use mechanize to log into megaupload

查看:71
本文介绍了使用机械化登录megaupload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码登录megaupload.我的问题是,我如何成功登录?我在代码末尾打印了当前URL,但是当我运行脚本时,它只会返回www.megaupload.com.

I am attempting to use the following code to log into megaupload. My question is, how do i that it successfully logged in? I print out the current URL at the end of the code, but when i run the script it just returns www.megaupload.com.

import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup
import html2text

# Browser
br = mechanize.Browser()

# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

# The site we will navigate into, handling it's session
br.open('http://www.megaupload.com/?c=login')

# Select the first (index zero) form
br.select_form('loginfrm')

#User credentials
br.form['username'] = 'USERNAMEGOESHERE'
br.form['password'] = 'PASSWORDGOESHERE'

br.submit()


#prints out the current log in
print br.geturl()

推荐答案

在响应正文中搜索错误消息:

Search the error message in the response body:

"Username and password do not match" in br.response().read()

或者检查您是否获得了预期的cookie(简单的示例,根据需要进行调整):

Or check if you got the expected cookie (simple example, tweak as needed):

any(c.domain == ".megaupload.com" and c.name == "user" for c in cj)

这篇关于使用机械化登录megaupload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆