Using Python to sign into website, fill in a form, then sign out

前端 未结 5 1653
挽巷
挽巷 2021-01-30 09:42

As part of my quest to become better at Python I am now attempting to sign in to a website I frequent, send myself a private message, and then sign out. So far, I\'ve managed to

5条回答
  •  伪装坚强ぢ
    2021-01-30 09:58

    You can use mechanize to work easily with this. This will ease your work of submitting the form. Don't forget to check with the parameters like name, title, message by seeing the source code of the html form.

    import mechanize
    br = mechanize.Browser()
    br.open("http://mywebsite.com/messages.php?action=send")
    br.select_form(nr=0)
    br.form['name'] = 'Enter your Name'
    br.form['title'] = 'Enter your Title'
    br.form['message'] = 'Enter your message'
    req = br.submit()
    

提交回复
热议问题