带有机械化功能的Python自动填充 [英] Python Auto Fill with Mechanize

查看:139
本文介绍了带有机械化功能的Python自动填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我还是分享一些代码,以自动使用机械化填充登录名( http://wwwsearch. sourceforge.net/mechanize/)?我想制作一个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.

谢谢!

推荐答案

这将帮助您登录到一个站点并下载一个页面,例如:

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')

此脚本假定您的登录表单是页面的第一页,输入名称为UsernamePassword.
您还可以使用以下名称来选择表单:

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")

请将该脚本调整为您喜欢的网站登录页面.
正如AlexMartelli所指出的那样,应将此脚本通用化以使用一些配置参数来处理不同的站点.

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.

这篇关于带有机械化功能的Python自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆