mechanize select form using id

后端 未结 7 1752
天命终不由人
天命终不由人 2020-12-18 18:31

I am working on mechanize with python.

The

7条回答
  •  眼角桃花
    2020-12-18 18:45

    g_form_id = ""
    
    
    def is_form_found(form1):
        return "id" in form1.attrs and form1.attrs['id'] == g_form_id
    
    
    def select_form_with_id_using_br(br1, id1):
        global g_form_id
        g_form_id = id1
        try:
            br1.select_form(predicate=is_form_found)
        except mechanize.FormNotFoundError:
            print "form not found, id: " + g_form_id
            exit()
    
    
    # ... goto the form page, using br = mechanize.Browser()
    
    # now lets select a form with id "user-register-form", and print its contents
    select_form_with_id_using_br(br, "user-register-form")
    print br.form
    
    
    # that's it, it works! upvote me if u like
    

提交回复
热议问题