2
我正在尝试使用以下代码登录到互联网快速浏览。我的问题是,我如何成功登录?我在代码的最后打印出当前的URL,但是当我运行该脚本时,它只返回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()
谢谢,其实我能够检查“欢迎用户名”。我试图加注你,但我是一个新用户,在我这样做之前我需要“15声望”。 – ChrisC 2010-12-12 20:02:06
@ user520574,你不能选择它作为答案吗?好吧,没关系。 – tokland 2010-12-12 20:04:19
我能够选择它作为答案,我之前没有看到该选项。再次感谢。 – ChrisC 2010-12-12 20:17:28