예제 #1
0
    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()
예제 #2
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('&nbsp;','')
		   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:
예제 #3
0
    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()
예제 #4
0
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])
'''
예제 #5
0
 def open(self, url, title):
     PAMIE(url)
     time.sleep(self.wait)
     win32gui.EnumWindows(self.enumHandler, title)
     self.isOpen = True