python : COM-IE 操作1
来源:互联网 发布:淘宝卖家用什么软件 编辑:程序博客网 时间:2024/05/16 06:51
- # -*- coding:UTF-8 -*-
- from time import sleep
- import win32com.client
- from win32com.client import DispatchEx
- class COM_IE:
- def __init__(self,url=None):
- self.url = url
- self.Visible = 1
- self.ie = self.openIE(url)
- def ExistIE(self,url):
- ShellWindowsCLSID = '{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
- ies=DispatchEx(ShellWindowsCLSID)
- if len(ies)==0:
- return None
- for ie in ies:
- if ie.LocationURL==url:
- return ie
- return None
- def NewIE(self,url):
- ie = DispatchEx("InternetExplorer.Application")
- ie.Visible = self.Visible
- ie.Navigate(url)
- return ie
- def openIE(self,url):
- ie = self.ExistIE(url)
- if ie==None:
- ie = self.NewIE(url)
- return ie
- def WaitIE(self):
- # while self.ie.Busy:
- # leep(1)
- while 1:
- state = self.ie.ReadyState
- if state ==4:
- # print "load done..."
- break
- sleep(1)
- def Visible(self):
- self.ie.Visible = self.Visible
- def GetBody(self):
- self.WaitIE()
- return self.ie.Document.body
- def GetNodes(self,parentNode,tag):
- """
- >>> coldiv=GetNodes(body,"div")
- """
- childNodes=[]
- for childNode in parentNode.getElementsByTagName(tag):
- childNodes.append(childNode)
- return childNodes
- def NodeByAttr(self,Nodes,nodeattr,nodeval):
- """
- >>> div_id_editor=NodeByAttr(coldiv,"id","editor_ifr")
- """
- for node in Nodes:
- if str(node.getAttribute(nodeattr))==nodeval:
- return node
- return None
- '''''
- def SetNodeHtml(self,node,val):
- node.innerHTML=val
- def SetNodeVal(self,node,val):
- node.value=val
- def NodeClick(self,node):
- node.click()
- '''
- def SetNodeHtml(self,body,node_type,node_attr,node_attr_val,node_inner_html):
- tags = self.GetNodes(body,node_type)
- node = self.NodeByAttr(tags,node_attr,node_attr_val)
- node.innerHTML = node_inner_html
- def SetNodeVal(self,body,node_type,node_attr,node_attr_val,node_value):
- tags = self.GetNodes(body,node_type)
- node = self.NodeByAttr(tags,node_attr,node_attr_val)
- node.value = node_value
- def NodeClick(self,body,node_type,node_attr,node_attr_val):
- tags = self.GetNodes(body,node_type)
- node = self.NodeByAttr(tags,node_attr,node_attr_val)
- node.click()
- def Quit(self):
- self.ie.Quit()
- if __name__=="__main__":
- url = "http://www.baidu.com/"
- IE = COM_IE(url)
- BODY = IE.GetBody()
- IE.SetNodeVal(BODY,"input","id","kw","agoago2009")
- IE.NodeClick(BODY,"input","id","su")
- raw_input('click enter to exit')
- IE.Quit()
0 0
- python : COM-IE 操作1
- python : COM-IE 操作2
- vc用com操作ie
- 使用COM简单操作IE
- python操作IE完整版
- python 操作IE
- COM-IE-(1)
- python : COM-IE 填充表单登录
- Python操作IE的代码
- python+win32+ie浏览器操作
- python IE自动化模块(模拟操作IE)
- Pamie模块详解 python操作ie浏览器
- Pamie模块详解 python操作ie浏览器
- 使用IE测试COM
- COM-IE-(2)
- 操作IE
- 完美Ajax类,支持事件,支持容器,支持多种操作方式,兼容ie,firefox http://bbs.51js.com/thread-65023-1-1.html
- C#操作IE浏览器 解决:COM 组件的调用返回了错误 HRESULT E_FAIL
- css自动换行,css代码
- poj1511 Atlantis(线段树+扫描线)
- 如何使用JS来改变CSS样式
- Google Chrome源码剖析【序】
- NoteBook Java实现记事本功能
- python : COM-IE 操作1
- 运行第一个spark程序
- python正则表达式
- python : COM-IE 操作2
- raid笔记
- Bash Shell中命令行选项/参数处理
- 今日夜谈--逻辑卷的那点事
- linux用户,组的介绍
- ATS 4.2.x records.config参数