def iepost(link,content): ie = PAMIE() ie.navigate(link) ie.setTextArea("content",content) ie.clickButton("发表评论") time.sleep(4) ie.quit()
def iepost(item, content): ie = PAMIE() ie.navigate(item) ie.setTextArea("content", content) ie.clickButton("发表评论") time.sleep(5) ie.quit()
def OperateACWebPage(self,bCA,lst): #global Obj_WaitDialog_Cancel #g_Group_Idx #define 'ie' object to control web page ie = PAMIE() #check version of IE. different version have different operate. nVer = self.getIEVersion(ie) if nVer == -1: log_public(WEB_ERR_NO_0002+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0002+dstURL[KEY_URL] return False #KillCA = True KillCA = bCA #loop to control every web page,all the control information storage at lst. #we loop to get page information at 'lst' to control web pages. #We call it one page_operate. lstLen = len(lst) for i in range(lstLen): #define 'lstSub',this list go to storage web page information. lstSub=[] lstSub.extend(lst[i]) #loop to control every control_components of one web page. #we loop to get control_components at 'lstSub' to control control_components of one web pages. #We call it line_operation. #Obj_WaitDialog_Cancel = 0 #if dialog popup after you click a button.you need to use WAIT DIALOG EVENT. This variable will starage the object. lstSubLen = len(lstSub) for j in range(0,lstSubLen): #get URL path #URL path is storage at '1' index of 'lstSubLen',so judge 'j' wether equal 1. if j == 0 : #define 'dstURL' as dictionary to storage URL and its value. dstURL={} dstURL.update(lstSub[j]) #URL Value can be None sometime,we will not go to the page when the value is 'NONE'. #if the value of 'KEY_URL' not NONE,we will got the page by 'navigate' function. if dstURL[KEY_URL]!=KEY_URL_NONE: ret = ie.navigate(dstURL[KEY_URL]) if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001+dstURL[KEY_URL] return False if KillCA == 'CAON': #IE 8 need to click 'overridelink' #IE 6 need to click 'CA authentication dialog' if nVer == 8: time.sleep(1) ret = ie.clickLink('overridelink') #encode if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001+dstURL[KEY_URL] return False KillCA = False #not need to kill next time open URL elif nVer == 6: time.sleep(1) KillCA = False else: #get line_operation. dstComb = {} dstComb.update(lstSub[j]) #if 'ASSIST' have '//',This line_operation will be ignore. if dstComb[KEY_ASSIST]== KEY_COMMENT: continue #dispatch line_operation.include kinds(set text box, set check box,select list box,...) Value = dstComb[KEY_CONTROLTYPE] if Value == KEY_WEB_TYPE_TEXTBOX: if ie.setTextBox(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0003+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0003+dstComb[KEY_CONTROLNAME] return False elif Value== KEY_WEB_TYPE_CHECKBOX: if self.MainCheckBox(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0004+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0004+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_LISTBOX: if self.MainListBox(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0005+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0005+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_BUTTON: if self.MainButton(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0006+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0006+dstComb[KEY_CONTROLNAME] False elif Value == KEY_WEB_TYPE_WAIT: if self.waitEvent(dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_JAVASCRIPT: if self.MainJavaScript(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0008+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0008+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_GROUP_CHECKBOX: if self.GetGoupCheckBoxIndex(ie,dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0009+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0009+dstComb[KEY_CONTROLNAME] return False #close ie after operation. ie.quit()
def setProxy(proxy): keyVal = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings' key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) SetValueEx(key, 'ProxyEnable', 0,REG_SZ,"1") SetValueEx(key, 'ProxyServer', 0, REG_SZ, proxy) CloseKey(key) setProxy('64.212.73.53:8080') from PAM30 import PAMIE import cModalPopUp import winGuiAuto ie = PAMIE() ie.navigate("http://gzjd.shenyangsheying.com/View.asp?id=20") ie.clickImage("give_ticket.jpg") ok=cModalPopUp.handlePopup("Confirm","È·¶¨") ok.start() ie.quit() ''' hwnd = winGuiAuto.findTopWindows("Windows Internet Explorer") for it in hwnd : control=winGuiAuto.dumpWindow(it) for item in control: if item[1]=='È·¶¨': winGuiAuto.clickButton(item[0]) '''
def run(self): ie1=PAMIE() while True: try: TotalAbstract='' page=pages.get() try: ie1.navigate(page) chunk=ie1.getPageText() except: try: ie1.navigate(page) chunk=ie1.getPageText() except: ie1.navigate(page) chunk=ie1.getPageText() print 'souping+'+page+'\n' soup=BeautifulSoup(chunk,fromEncoding='GBK') soup1=soup.find('div',{"class":"baogaonews"}) chunks=soup1.findAll('td') stockName=chunks[1].find('b').string #股票名称 if stockName==None: stockName=str(stockName) print stockName+'\n' reportAuthor=chunks[3].find('b').string #研究报告作者 if reportAuthor==None: reportAuthor=str(reportAuthor) print reportAuthor+'\n' stockCode=chunks[6].find('b').string #股票代码 if stockCode==None: stockCode=str(stockCode) print stockCode+'\n' reportBelongCompany=chunks[8].find('b').string #研究报告出处 if reportBelongCompany==None: reportBelongCompany=str(reportBelongCompany) print reportBelongCompany+'\n' rateLevel=chunks[11].find('b').string #推荐评级 if rateLevel==None: rateLevel=str(rateLevel) print rateLevel+'\n' reportType=chunks[13].find('b').string #研究报告栏目 if reportType==None: reportType=str(reportType) print reportType+'\n' Title=soup.find('strong').string print Title+'\n' time=chunks[18].find('b').string tmptimes=time.split(' ') time=tmptimes[0] timechunks=time.split('-') if len(timechunks)==3: if len(timechunks[1])==1: timechunks[1]='0'+timechunks[1] if len(timechunks[2])==1: timechunks[2]='0'+timechunks[2] time=timechunks[0]+timechunks[1]+timechunks[2] Title=Title ContentAbstractArea=soup.find('div',{"class":"new_content"}) if ContentAbstractArea !=None: tmp=ContentAbstractArea.find('td') tmpStr=str(tmp) abstract=tmpStr[34:-12].replace('<font style="DISPLAY:none;"><a href="http://www.microbell.com/">www.microbell.com</a>(\xe8\xbf\x88\xe5\x8d\x9a\xe6\xb1\x87\xe9\x87\x91)\xe3\x80\x82</font>','\n') abstract=abstract.replace(' ','') abstract=abstract.replace('<br />','') abstract=abstract.replace('\n','') TotalAbstract=TotalAbstract+abstract+'\n' ##INSERT THE INFO TYPE:GBK print '#################################' try: self.cursor.execute("insert into MBStrategy values('%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(page,Title,TotalAbstract.decode('utf-8'),time,reportAuthor,stockCode,reportBelongCompany,rateLevel,reportType)) self.conn.commit() except Exception,e: print e print '************************************' except:
def run(self): ie=PAMIE() urlre=re.compile('docdetail_.*html') while True: try: host=hosts.get() try: #url=urllib2.urlopen(host) ie.navigate(host) chunk=ie.getPageText() except: try: ie.navigate(host) chunk=ie.getPageText() except: ie.navigate(host) chunk=ie.getPageText() print 'souping+'+host+'\n' links=urlre.findall(chunk) for link in links: totallink='http://www.microbell.com/'+link if not self.isindexed(totallink): pages.put(totallink) #soup=BeautifulSoup(chunk,fromEncoding='GBK') #areas=soup.findAll('div',{"class":"classbaogao_sousuo_new"}) #print '##########################' #for area in areas: # link=area.find('a',href=True)['href'] # totallink='http://www.microbell.com/'+link # if not self.isindexed(totallink): # pages.put(totallink) # print 'END***************' except: writeindex=file('hostsErro.txt','a+') writeindex.write(host+'\n') writeindex.close() continue ie.quit()
from _winreg import * def setProxy(proxy): keyVal = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings' key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) SetValueEx(key, 'ProxyEnable', 0, REG_SZ, "1") SetValueEx(key, 'ProxyServer', 0, REG_SZ, proxy) CloseKey(key) setProxy('64.212.73.53:8080') from PAM30 import PAMIE import cModalPopUp import winGuiAuto ie = PAMIE() ie.navigate("http://gzjd.shenyangsheying.com/View.asp?id=20") ie.clickImage("give_ticket.jpg") ok = cModalPopUp.handlePopup("Confirm", "È·¶¨") ok.start() ie.quit() ''' hwnd = winGuiAuto.findTopWindows("Windows Internet Explorer") for it in hwnd : control=winGuiAuto.dumpWindow(it) for item in control: if item[1]=='È·¶¨': winGuiAuto.clickButton(item[0]) '''
from PAM30 import PAMIE ie = PAMIE() ie.navigate('http://jw.nwpu.edu.cn/') #print ie.cookieGet() ie.buttonExists('btnSure') ie.setTextBox('zjh', '2011300020') ie.setTextBox('mm', 'dq012369') ie.clickButton('btnSure') ie.navigate('http://jw.nwpu.edu.cn/jxpgXsAction.do?oper=listWj') #ie.executejavaScript("javascript:submitMe()") ie.clickButtonImage( u'0000000076#@1989000019#@吴立言#@学生课堂教学评价问卷#@机械原理与设计#@0520130')
import win32com from PAM30 import PAMIE import time import winGuiAuto #popup window """ hwnd = winGuiAuto.findTopWindows("Windows Internet Explorer") control_list=winGuiAuto.dumpWindow(hwnd[0]) for control_item in control_list: if control_item[1]='OK': winGuiAuto.clickButton(control_item[0]) """ ret = False ie = PAMIE() #Open login page of AC ret = ie.navigate('https://192.168.4.232') if ret == False: ie.quit() #ie.navigate('http://www.baidu.com') #skip auth page ie.clickLink('overridelink') time.sleep(1) #login AC ie.setTextBox('UserName', 'icac')#set user name ie.setTextBox('PassWord', 'icaclogin')#set user name
# -*- coding: UTF-8 -*- import win32com from PAM30 import PAMIE import time import winGuiAuto #popup window """ hwnd = winGuiAuto.findTopWindows("Windows Internet Explorer") control_list=winGuiAuto.dumpWindow(hwnd[0]) for control_item in control_list: if control_item[1]='OK': winGuiAuto.clickButton(control_item[0]) """ ret = False ie = PAMIE() #Open login page of AC ret = ie.navigate('https://192.168.4.232') if ret == False: ie.quit() #ie.navigate('http://www.baidu.com') #skip auth page ie.clickLink('overridelink') time.sleep(1) #login AC ie.setTextBox('UserName', 'icac') #set user name ie.setTextBox('PassWord', 'icaclogin') #set user name
from PAM30 import PAMIE ie = PAMIE() ie.navigate('http://jw.nwpu.edu.cn/') #print ie.cookieGet() ie.buttonExists('btnSure') ie.setTextBox('zjh','2011300020') ie.setTextBox('mm','dq012369') ie.clickButton('btnSure') ie.navigate('http://jw.nwpu.edu.cn/jxpgXsAction.do?oper=listWj') #ie.executejavaScript("javascript:submitMe()") ie.clickButtonImage(u'0000000076#@1989000019#@吴立言#@学生课堂教学评价问卷#@机械原理与设计#@0520130')
def OperateACWebPage(self, bCA, lst): #global Obj_WaitDialog_Cancel #g_Group_Idx #define 'ie' object to control web page ie = PAMIE() #check version of IE. different version have different operate. nVer = self.getIEVersion(ie) if nVer == -1: log_public(WEB_ERR_NO_0002 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0002 + dstURL[KEY_URL] return False #KillCA = True KillCA = bCA #loop to control every web page,all the control information storage at lst. #we loop to get page information at 'lst' to control web pages. #We call it one page_operate. lstLen = len(lst) for i in range(lstLen): #define 'lstSub',this list go to storage web page information. lstSub = [] lstSub.extend(lst[i]) #loop to control every control_components of one web page. #we loop to get control_components at 'lstSub' to control control_components of one web pages. #We call it line_operation. #Obj_WaitDialog_Cancel = 0 #if dialog popup after you click a button.you need to use WAIT DIALOG EVENT. This variable will starage the object. lstSubLen = len(lstSub) for j in range(0, lstSubLen): #get URL path #URL path is storage at '1' index of 'lstSubLen',so judge 'j' wether equal 1. if j == 0: #define 'dstURL' as dictionary to storage URL and its value. dstURL = {} dstURL.update(lstSub[j]) #URL Value can be None sometime,we will not go to the page when the value is 'NONE'. #if the value of 'KEY_URL' not NONE,we will got the page by 'navigate' function. if dstURL[KEY_URL] != KEY_URL_NONE: ret = ie.navigate(dstURL[KEY_URL]) if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001 + dstURL[KEY_URL] return False if KillCA == 'CAON': #IE 8 need to click 'overridelink' #IE 6 need to click 'CA authentication dialog' if nVer == 8: time.sleep(1) ret = ie.clickLink('overridelink') #encode if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001 + dstURL[ KEY_URL] return False KillCA = False #not need to kill next time open URL elif nVer == 6: time.sleep(1) KillCA = False else: #get line_operation. dstComb = {} dstComb.update(lstSub[j]) #if 'ASSIST' have '//',This line_operation will be ignore. if dstComb[KEY_ASSIST] == KEY_COMMENT: continue #dispatch line_operation.include kinds(set text box, set check box,select list box,...) Value = dstComb[KEY_CONTROLTYPE] if Value == KEY_WEB_TYPE_TEXTBOX: if ie.setTextBox(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0003 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0003 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_CHECKBOX: if self.MainCheckBox( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0004 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0004 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_LISTBOX: if self.MainListBox( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0005 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0005 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_BUTTON: if self.MainButton(ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0006 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0006 + dstComb[ KEY_CONTROLNAME] False elif Value == KEY_WEB_TYPE_WAIT: if self.waitEvent(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0007 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0007 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_JAVASCRIPT: if self.MainJavaScript( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0008 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0008 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_GROUP_CHECKBOX: if self.GetGoupCheckBoxIndex( ie, dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0009 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0009 + dstComb[ KEY_CONTROLNAME] return False #close ie after operation. ie.quit()
# coding:utf-8 # __author__ = 'Mark sinoberg' # __date__ = '2016/7/7' # __Desc__ = 模拟IE进行网页的点击。在同一目录下必须包含PAM30这个py文件 from PAM30 import PAMIE ie = PAMIE() # for i in range(1,100,1): # ie.navigate('http://blog.csdn.net/marksinoberg/article/details/51852241') # ie.refresh() # ie.quit() ie.navigate('https://github.com/login') ie.setTextBox('login', '*****@*****.**') ie.setTextBox('password', 'guoruibiao285514') ie.clickButton('commit')
def open(self, url, title): PAMIE(url) time.sleep(self.wait) win32gui.EnumWindows(self.enumHandler, title) self.isOpen = True
# -*- coding: utf-8 -*- from PAM30 import PAMIE import time from datetime import datetime now = datetime.now() contentstr = "今天的测试" + str(now) ie = PAMIE() time.sleep(3) ie.navigate("http://www.dianping.com/login") time.sleep(3) ie.setTextBox("username", "snowman1985") ie.setTextBox("password", "") validatecode = raw_input("please enter validate code:") ie.setTextBox("validate", validatecode) validelem = ie.findElement("input", "name", "login") ie.clickElement(validelem) time.sleep(1) raw_input("wait for login enabled") ie.clickButton("login") time.sleep(2) print "#### after login" ie.navigate("http://www.dianping.com/msg/send") time.sleep(3) ie.setTextBox("targetName", "山水之间的雪人") ie.setTextArea("content", contentstr) sendbut = ie.findElement("input", "type", "submit") ie.clickElement(sendbut)
from PAM30 import PAMIE ie = PAMIE() s = 40 while s: s = str(s) ie.navigate( 'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%%E6%%8E%%A7%%E5%%88%%B688-%s.ppt' % s) s = int(s) s -= 1 # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-02.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-03.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-04.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-05.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-06.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-07.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-08.ppt') # ie.navigate(r'http://jpkc.nwpu.edu.cn/jpkc2005/03/resources2014/PPT88/%E6%8E%A7%E5%88%B688-09.ppt') #print ie.cookieGet() # ie.buttonExists('btnSure') # ie.setTextBox('zjh','2011300020') # ie.setTextBox('mm','dq012369') # ie.clickButton('btnSure') # ie.navigate('http://jw.nwpu.edu.cn/jxpgXsAction.do?oper=listWj') # #ie.executejavaScript("javascript:submitMe()") # ie.clickButtonImage(u'0000000076#@1989000019#@吴立言#@学生课堂教学评价问卷#@机械原理与设计#@0520130')