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 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 ......
import sys
import os
import datetime
import time
class ArgsDealwith:
def arg_environment(self, args):
filepath = ('PYTHON_PATH', 'path')
for i in filepath:
&nbs ......
一个Python脚本的开发全过程
问题:完成一个可以为我们所有的重要程序做备份的程序。
步骤拆解:
需要备份的文件和目录由一个列表指定。
文件备份成一个zip文件。
zip存档的名称是当前的日期和时间。
我们使用标准的zip命令,它通常默认地随Linux/Unix发行版提供。Windows用户可以使用Info-Zip程序。注意 ......
学习了第八章后,紧锣密鼓的开始第九章的学习。
学习了“数据结构操作”,学习了“文件操作”。“数据结构操作”还比较有意思,看得懂。“文件操作”就开始头昏昏的,像脑子进了浆糊。
好不容易看到“操作程序”,才发现“操作程序”这一节的内容并不是我所 ......
http://www.cppblog.com/jacky2019/archive/2007/05/17/24269.html
c++中嵌入python入门1
本人是用vc2003+python2.5学习的,其它的也应该差不了多少
0. 坏境设置
把python的include/libs目录分别加到vc的include/lib directories中去。另外,由于python没有提供debug lib,体地说,就是没有提供python25_d.lib了。你可 ......