我需要知道点击登录按钮的代码,但有 2 个相同形式的按钮,我需要语法并且我正在使用请求
下面是代码
URL = 'https://apps1.coned.com/cemyaccount/NonMemberPages/Login.aspx'
session = requests.session()
login_data = {
'ctl00_Main_Login1_UserName': USERNAME,
'ctl00_Main_Login1_Password': PASSWORD,
'ctl00_Main_Login1_LoginButton': 'Sign In',
}
r = session.post(URL, data=login_data)
r = session.get("https://apps1.coned.com/cemyaccount/MemberPages/MyAccounts.aspx?lang=eng")
print r.content
所以当我登录后打印这个时,它仍然打印登录页面而不是登录页面
以前我使用机械化:
import mechanize
br=mechanize.Browser()
br.open('https://apps1.coned.com/cemyaccount/NonMemberPages/Login.aspx')
br.select_form(nr=0)
br['ctl00$Main$Login1$UserName']= ""
br['ctl00$Main$Login1$Password']= ""
br.submit()
a = 'https://apps1.coned.com/cemyaccount/MemberPages/MyAccounts.aspx?lang=eng'
ab = br.open(a).read()
print ab
由于这是打印登录页面,因为有 2 个提交按钮,并且上面的代码正在点击表单提交按钮,所以我将其修改为
from mechanize import Browser
import mechanize
br = mechanize.Browser()
br.open('https://apps1.coned.com/cemyaccount/NonMemberPages/Login.aspx')
br.select_form(nr=0)
br['ctl00$Main$Login1$UserName']= ""
br['ctl00$Main$Login1$Password']= ""
submit_response = br.submit(name='ctl00$Main$Login1$LoginButton', label='Sign In')
a = 'https://apps1.coned.com/cemyaccount/MemberPages/MyAccounts.aspx?lang=eng'
ab = br.open(a).read()
print ab
但它仍在打印登录页面。
有人能帮我吗。