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

python脚本模拟浏览器

(偶尔看到,怕忘了)
仿用户打开浏览器然后点击等行为然后获取结果,以下是我使用过的方法只是依赖与ie不过firefox等应该也有相应的调用方法:
思路就是调用ie的com组件然后就是对dom的操作跟用javascript操作dom类似,示范代码如下
#天涯登陆地址
tianyalogin = "http://www.tianya.cn/"
tianya_user = "xxxxx"
tianya_pw = "xxxxx"
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 0
#开始登陆
ie.Navigate(tianyalogin)
state = ie.ReadyState
print "打开登陆页面"
while 1:
state = ie.ReadyState
if state ==4:
break
sleep(1)
print "页面载入完毕,输入用户名密码"
state = None
ie.Document.getElementById("text1").value=tianya_user
ie.Document.getElementById("password1").value=tianya_pw
ie.Document.getElementById("button1").click()
while 1:
state = ie.ReadyState
print state
if state ==4 and str(ie.LocationURL) == "http://
cache.tianya.cn/index.htm":
break
sleep(1)
print "登陆成功"



相关文档:

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笔记(5)

模块
 
一.简介
模块基本上就是一个包含了所有你定义的函数和变量的文件。为了在其他程序中重用模块,模块的文件名必须以.py为扩展名。
 
例如:
 
#!/usr/bin/python
# Filename: using_sys.py
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n ......

Python内建函数之——filter,map,reduce

     在讲述filter,map和reduce之前,首先介绍一下匿名函数lambda。
     lambda的使用方法如下:lambda [arg1[,arg2,arg3,...,argn]] : expression
     例如:
     >>> add = lambda x,y : x + y
>>> add ......

Python字符串编码

在Python中有些特殊的地方是存在两种字符串,分别为str和unicode字符串,他们都继承自basestring。
如:s="hello world",s为str;us=u"hello world",us为unicode。
使用help(str)和help(unicode)可以查看各自说明,他们都有decode、encode方法,
decode用于将str字符串解码为unicode字符串,
encode用于将unicode字符 ......

python 字节码指令列表

/***********************************************************
KVS:文件:opcode.h
swith字节码指令的文件:ceval.c
************************************************************/
/* KVS:字节码指令列表Instruction opcodes for compiled code */
#define STOP_CODE 0
#define POP_TOP  1
#def ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号