使用python mechanize库登录https站点 [英] logging into https site using python mechanize library
问题描述
我有以下代码:
import requests
import sys
import urllib2
import re
import mechanize
import cookielib
#import json
#import imp
#print(imp.find_module("requests"))
#print(requests.__file__)
EMAIL = "******"
PASSWORD = "*******"
URL = 'https://www.imleagues.com/Login.aspx'
address = "http://www.imleagues.com/School/Team/Home.aspx?Team=27d6c31187314397b00293fb0cfbc79a"
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.add_password(URL, EMAIL, PASSWORD)
br.open(URL)
#br.open(URL)
#br.select_form(name="aspnetForm")
#br.form["ctl00$ContentPlaceHolder1$inUserName"] = EMAIL
#br.form["ctl00$ContentPlaceHolder1$inPassword"] = PASSWORD
#response = br.submit()
#br= mechanize.Browser()
site = br.open(address)
# Start a session so we can have persistant cookies
#session = requests.Session()
# This is the form data that the page sends when logging in
#login_data = {
# 'ctl00$ContentPlaceHolder1$inUserName': EMAIL,
# 'ctl00$ContentPlaceHolder1$inPassword': PASSWORD,
# 'aspnetFrom': 'http://www.imleagues.com/Members/Home.aspx',
#}
#URL_post = 'http://www.imleagues.com/Members/Home.aspx'
# Authenticate
#r = session.post(URL, data=login_data)
# Try accessing a page that requires you to be logged in
#r = session.get('http://www.imleagues.com/School/Team/Home.aspx?Team=27d6c31187314397b00293fb0cfbc79a')
website = site.read()
f = open('crypt.txt', 'wb')
f.write(website)
#print(website_html)
我正在尝试登录此网站来监控游戏时间并确保它们不是'我改变了(再次)。我已经尝试了各种方法来做到这一点,大多数都在上面注释,但所有这些方法都将我重定向回登录页面。有任何想法吗?谢谢。
I am trying to log into this site to monitor game times and make sure they aren't changed on me (again). I've tried various ways to do this, most commented out above, but all of them redirect me back to the login page. Any ideas? Thanks.
推荐答案
正如我在给定网站上看到的登录按钮不在提交
标签。登录是javascript函数
As I see in given website login button is not in submit
tag. Login is javascript function
< a ... href =javascript:__ doPostBack('ctl00 $ ContentPlaceHolder1 $ btnLogin','') < / a>
和 mechanize
无法处理javascript。我遇到了类似的问题并提出了使用 Spynner $ c $的解决方案C>
。
它是无头网络浏览器。因此,您可以使用机械化来完成相同的任务,并且它具有javascript支持。
and mechanize
cannot handle javascript. I faced very similiar problem and came up with solution to use Spynner
.
It is headless web browser. So you can acomplish same tasks as you use mechanize and it has javascript support.
这篇关于使用python mechanize库登录https站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!