python time模塊,python控制瀏覽器模塊_Pamie模塊詳解 python操作ie瀏覽器

 2023-10-08 阅读 36 评论 0

摘要:此文檔使用平臺為 cPAMIE Build 2.0,和之前的版本有明顯的差別,具體可直接看cPAMIE.py 源碼下面是一些常用的方法ie.navigate('http://blog.alexa.cn') 用來訪問一個鏈接。python time模塊?ie.linkClick('linkname') 打開這個頁面中的一個連接 參數: name或

此文檔使用平臺為 cPAMIE Build 2.0,和之前的版本有明顯的差別,具體可直接看cPAMIE.py 源碼

下面是一些常用的方法

ie.navigate('http://blog.alexa.cn') 用來訪問一個鏈接。

python time模塊?ie.linkClick('linkname') 打開這個頁面中的一個連接 參數: name或 id

ie.textBoxSet('labels','python') 設置一個文本域的值。第一個參數為文本域的名稱,第二個參數為要輸入的值,

ie.buttonClick('btnA') 用來模擬點擊按鈕 參數是按鈕的名字

python模塊導入、ie.findText(unicode("登錄", "cp936")) 查找文本 如:

if (True == ie.findText(unicode("非法登錄", "cp936"))):

print "非法登錄!"

python re模塊?else:

print "登錄成功!"

ie.quit() -- 關閉打開的ie

日常辦公會用到的python模塊。ie.goBack() -- 后退

ie.refresh() -- 刷新

ie.buttonGetValue('wp-submit','value') 得到一個無素的其它值,第一個參數為你知道的元素屬性如:id, name, value 等,第二個參數為你要得到的這個元素的其它值,這樣如果你知道name,就可得到id,value等,如果知道name就可知道id,value.....

python常用模塊?ie.buttonClick('down') 這個方法的參數可以是name,ID,VALUE等,注:NAME和VALUE為中文時記著轉碼如:unicode("斷線", "cp936")

ie.elementsGetList(tag, [filter], ) 返回一個過濾后的元素列表

符幾個例子:

python 安裝?這個是將文章提交給GOOGLE收藏夾的腳本,用法 postgoogle.py?http://blog.alexa-pro.cn/index.php

importcPAMIE,re,string,time,sys

ie=?cPAMIE.PAMIE()

python 類、args?=?sys.argv

ie.navigate(args[1])

Title=ie.locationName().strip()

Title=Title.replace('GGclub','').replace('?Blog?Archive?','')

ie.navigate('https://www.google.com/accounts/Logout?continue=http://www.google.com/intl/zh-CN/&hl=zh-CN')

ie.navigate('https://www.google.com/accounts/ServiceLogin?hl=zh-

CN&continue=http://www.google.com/bookmarks/mark%3Fop%3Dadd%26bkmk%3Dhttp%253A%252F%252Fblog.alexa-pro.cn%252F%

26title%3DGGclub&nui=1&service=bookmarks')

ie.textBoxSet('Email','yingguang08@gmail.com')

ie.textBoxSet('Passwd','*******')

ie.buttonClick('signIn')

ie.textBoxSet('title',Title)

ie.textBoxSet('bkmk',args[1])

ie.textBoxSet('labels','python')

ie.textBoxSet('annotation','python?linux')

ie.buttonClick('btnA')

解釋:

先執行退出操作,以免現在是登陸狀態 而報錯

ie.navigate('https://www.google.com/accounts/Logout?continue=http://www.google.com/intl/zh-CN/&hl=zh-CN')

下面是一個為做網賺的朋友做的小腳本,實現了

在登陸狀態下http://www4.bux.to , 列出要點擊的連接,進行點擊操作,每個點擊后持續40秒后再點下一個

importcPAMIE,re,time

ie=?cPAMIE.PAMIE()

Url='http://www4.bux.to/surf.php'

ie.navigate(Url)

cc=ie.outerHTML()

cc?=?re.findall('''''target=_blank>(.*?)''',cc)

forclickincc:

printclick

ie.linkClick(click)

time.sleep(40)

AM30, 操作IE的好幫手

在python下,大家可能需要操作IE訪問網站。也許有人要問了,我們有很多優秀的網站訪問插件呀,比如之前提到的?mechanize? ???其實大家仔細看 mechanize 就知道了,它是不支持 js 操作的。雖然我們很多時候可以通過模擬 js 的業務邏輯來模擬。但是也有極端的情況下是無法做到的。比如,你需要向一個網站投遞新聞,而同時需要輸入驗證碼。而且這個新聞呢,也必須注意格式,也就是 說投遞者本人必須看到內容,同時可以做修改。那這樣的情況,mechanize就無能為力了。? ???廢話不多說,進入正題。讓我來介紹今天的主角 PAMIE.?? ???PAMIE使用 依賴于 win32com??這個組件。在此基礎上操作IE. 附件中提供 win32com 及 PAMIE 供大家下載簡單的例子:

import PAM30

ie = PAM30.PAMIE()

ie.navigate('www.google.com')

ie.setTextBox('q','PAMIE')

ie.clickButton('btnG')復制代碼? ?? ?但是我們實際使用中,實際上會碰到許多的控件。如,input ,radio ,checkbox.下面針對不同控件給出函數列表, 大家看名字大概就應該明白是干什么的. 權當手冊使用吧,呵呵 :狀態控制? ?? ? 實際應用中,需要考慮IE的狀態,比如訪問一個網頁,隨即進行操作,在網頁未下載完成的情況下,容易出錯? ?? ? PAMIE 則考慮到下面的情況

_wait()??: 等待整個頁面下載完成

_frameWait() :??等待一個frame下載完成

_docGetReadyState:??獲取文檔對象的狀態復制代碼TextArea

getTextArea (name):? ? 獲取一個textarea,可能使用 id,name 或者 index

getTextAreaValue(name, attribute):? ?獲取一個textarea的屬性值

getTextAreasValue() 獲取所有textarea

setTextArea(name): 給textarea賦值

textAreaExists(name): 查看指定名稱的textarea 是否存在復制代碼Input

getTextBox(name):

getTextBoxValue(name, attribute):

getTextBoxes():

getTextBoxesValue()

setTextBox( name, value):

getInputElements():復制代碼Button

buttonExists(self, name):??檢查一個button是否存在

clickButton(self, name):? ?點擊一個按鈕, name 可以是 name,id,index甚至是value屬性的值

clickButtonImage(self, name):??同上,點擊一個圖片按鈕復制代碼Radio

getRadioButton(name):

def getRadioButtonSelected(name):

getRadioButtonValues(name):

getRadioButtons():復制代碼CheckBox

checkBoxExists(self, name): 檢查一個單選框是否存在復制代碼ListBox

getListBox(name):

getListBoxItemCount(name):

getListBoxOptions(name):

getListBoxSelected(name):

getListBoxValue(name, attribute):

listBoxUnSelect(name, value):

selectListBox(name, value):復制代碼Image

getImage( name):

getImageValue(name, attribute):

getImages():

getImagesValue( attribute):

imageExists(name):復制代碼form

formExists( name):

getForm( name=None):

getFormValue( name, attribute):

getFormVisibleControlNames( name=None):

getForms():

getFormsValue( attribute):復制代碼a

clickHiddenLink( name):

getLink( name):

getLinkValue( name, attribute):

getLinks( filter=None):復制代碼table

getTable( name):

getTableData( name):

getTableRowIndex( name, row):

getTableText(tableName,rownum,cellnum, frameName=None):

getTables( filter=None):

tableCellExists( tableName, cellText):

tableExists( name):

tableRowExists( name, row):復制代碼div

divExists( name):

getDiv( name):

getDivValue( name, attribute):

getDivs():

getDivsValue( attribute):復制代碼通用 Element

clickElement( element):??點擊一個節點。

clickHiddenElement( element):

findElement( tag, attributes, val, elementList=None):

findElementByIndex( tag, indexNum, filter=None, elementList=None):

findText( text):

fireElementEvent( tag, controlName, eventName):

textFinder(text):

getElementChildren( element, all=True):

getElementParent( element):

getElementValue( element, attribute):

getElementsList( tag, filter=None, elementList=None):復制代碼操作類函數:? ?? ?用于控制IE的動作

navigate( url):

changeWindow( wintext):??轉而控制另外一個窗體對象

pause( string = "Click to Continue test"):

goBack(self):

findWindow( title, indexNum=1):

closeWindow( title=None):

refresh(self):

resize( iWidth, iHeight):

quit(self):復制代碼信息資源類:? ?? ? 獲取當前IE的屬性

getIE(self):

getPageText(self):

locationURL(self):

outerHTML(self):

randomString( length):

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/140114.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息