How to login to a website with python and mechanize

前端 未结 2 2100
南笙
南笙 2020-12-24 03:17

i\'m trying to log in to the website http://www.magickartenmarkt.de and do some analyzing in the member-area (https://www.magickartenmarkt.de/?mainPage=showWants). I saw oth

相关标签:
2条回答
  • 2020-12-24 03:38

    Why not use a browser instance to facilitate navigation? Mechanize also has the ability to select particular forms (e.g. nr = 0 will select the first form on the page)

    browser = mechanize.Browser()
    browser.open(YOUR URL)
    browser.select_form(nr = 0)
    browser.form['username'] = USERNAME
    browser.form['password'] = PASSWORD
    browser.submit()
    
    0 讨论(0)
  • 2020-12-24 03:49

    Web automation ? Definitely "WEBBOT"

    webbot works even for webpages with dynamically changing id and classnames and has more methods and features than selenium.

    Here's a snippet :)

    from webbot import Browser 
    web = Browser()
    web.go_to('google.com') 
    web.click('Sign in')
    web.type('mymail@gmail.com' , into='Email')
    web.click('NEXT' , tag='span')
    web.type('mypassword' , into='Password' , id='passwordFieldId') # specific selection
    web.click('NEXT' , tag='span') # you are logged in ^_^
    
    0 讨论(0)
提交回复
热议问题