python自动填充网页_使用机械化的Python自动填充

Could someone help me or share some code to auto fill a login with mechanize (http://wwwsearch.sourceforge.net/mechanize/)? I want to make a python script to log me into my favorite sites when I run it.

Thanks!

解决方案

This will help you to login to one site and download a page for example:

import mechanize

br=mechanize.Browser()

br.open('http://www.yourfavoritesite.com')

br.select_form(nr=0) #check yoursite forms to match the correct number

br['Username']='Username' #use the proper input type=text name

br['Password']='Password' #use the proper input type=password name

br.submit()

br.retrieve('https://www.yourfavoritesite.com/pagetoretrieve.html','yourfavoritepage.html')

This script presumes that your login form is the first of the page and the input names are Username and Password.

You could also select your form by name with:

br.select_form(name="thisthing")

Please, adapt this script to your favorite site login page.

As well pointed by AlexMartelli, this script should be generalized to handle different sites with some config parameters.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值