3

我试图登录到一个站点https://everest.ioe.edu.np/lanusers/dialup.php ,然后单击“更改密码”链接,使用 mechanize 更改密码并使用以下代码注销:

import mechanize        

def tryinglogin():
    browser = mechanize.Browser(factory=mechanize.RobustFactory())
    browser.set_handle_robots(False)
    r = browser.open("https://everest.ioe.edu.np/lanusers/dialup.php") #surfing web page
    browser.select_form(nr=0)               # Find first form of web page
    browser.form["name"] = "067bce001"
    browser.form["password1"] = "abc"    
    pass="password1"
    browser.submit()                    # submit

    html = browser.response().readlines()       # Read the response, html 
    for i in range(0,len(html)):
    if '<u>Your current LAN account status</b>' in html[i]:  # filter    out one line 
        print(html[i])


    browser.find_link(text='Change password')
    req = browser.click_link(text='Change password')
    browser.open(req)
#print browser.response().read()     #print html of logged in page

  r = browser.open(req)                #  surfing web page ,no problem upto here in code
  browser.select_form(nr=0)             
  browser.form["password"] = "abc"
  browser.form["password1"] = "bcdef"  # change password field  
  browser.form["password2"] = "bcdef"   #verify password field
  browser.submit()      

if __name__ == "__main__":
    tryinglogin()

代码成功登录,单击更改密码链接,然后转到更改密码页面,但随后显示“ParseError:嵌套表单错误”

请大师帮我弄清楚为什么我的机器人不工作。

4

0 回答 0