易截截图软件、单文件、免安装、纯绿色、仅160KB

Python cPAMIE 模拟IE浏览器

 
PAMIE 是一个很有意思的模块。它是一个实现IE自动化的模块。在此之前我使用过ClientCookie这个模块,它可以使用urllib2来通过程序访问页面,并且很适合在需要cookie支持的环境中。不过,有些web的访问过程并不仅仅是下载文件这样的事情,有时是一系统的动作。PAMIE应该是一个更直观,更简单的模拟手工输入的过程。不过,局限就是它只支持IE,在某些特殊情况下还是可以的。
使用它的话你需要安装win32all模块。
下面是它的readme提供的一个简单示例:
import cPAMIE
ie= cPAMIE.PAMIE()
# Start Script:
ie.Navigate ('http://pamie.sourceforge.net/pamieform.html')
ie.SetTextBox('John','firstname',0)
ie.SetTextBox('Doe','lastname',0)
ie.SetTextBox('1020 State Street','Addline1',0)
ie.SetTextBox('Suite #16','Addline2',0)
ie.SetTextBox('San Mateo','city',0)
ie.SetListBox('CA','state',0)
ie.SetTextBox('90210','zip',0)
ie.ClickButton('Submit',0)
那么在我们下载完这个模块之后,它是一个zip包。它没有做成安装模式,可以自行将cPAMIE.py拷贝到python安装目录下的lib子目录中即可。上面的代码很简单,先导入cPAMIE模块,然后生成一个自动化对象ie。这时我们会看到程序自动打开一个ie窗口,我们的操作可以在这个ie窗口中看到,执行的部分以黄底显示。
ie.Navigate()用来访问一个链接。
ie.SetTextBox()用来设置一个文本域的值。第一个参数为输入的值,第二个参数为对应的form表格的Input域的名字(这一点需要查看源码才知识),第三个是form的名字(示例为0表示下标)。
ie.SetListBox()用来设置列表框的值。
ie.ClickButton()用来模拟点击按钮。第一个参数是按钮的名字,第二个参数为0表示下标。
在PAMIE主页中写出了一些可用的其它的方法,如ClickLink()。它的第一个参数为链接对应的文本,如果是中文,转成unicode即可。如页面是GB2312,链接源码为:
<a href="http://xxx.com/">汉字</a>
调用如下:
ie.ClickButton(unicode('汉字', 'cp936'))
在实际运行中可能不需要这样,只要参数是unicode编码即可。
同时如果你查看源码,还可以看到一些其它的方法:
Quit() -- 关闭打开的ie
GoBack() -- 后退
Refresh() -- 刷新
一边操作一边就可以看到结果,很简单也很方便。


相关文档:

python中的列表排序操作

 
 
 
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......

Python Socket 编程

client:
import socket, sys
if __name__ == '__main__':
    #处理参数
    argv = sys.argv
    if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
        print '>>>Useage:', argv[0], '<address> < ......

Python: 使用装饰器“@”取得函数执行时间

  Python中可以使用装饰器对函数进行装饰(或说包装),利用这个特性,可以很方便、简洁地解决一些问题,比如获得函数执行时间的问题。
  首先,我们定义一个函数,如下:
  def exeTime(func):
def newFunc(*args, **args2):
t0 = time.time()
print "@%s, {%s} start" % (time.strftime("%X", time.local ......

python的wiki 列子.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""显示正常页面,对页面的文字做特殊的链接处理"""
......

Python 定时运行脚本

import sys
import os
import datetime
import time
class ArgsDealwith:
   
    def arg_environment(self, args):
        filepath = ('PYTHON_PATH', 'path')
        for i in filepath:
 &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号