Esempio n. 1
0
 def __init__(self,dbConnection):
     self._mainUrl = "https://finance.Fineco.com/q/hp?s=%s"
     self.dbAdapter = FinecoDBAdapter(dbConnection)
Esempio n. 2
0
class FinecoScraper:
    SCRAPER_CODE = "FINECO"
    
    def __init__(self,dbConnection):
        self._mainUrl = "https://finance.Fineco.com/q/hp?s=%s"
        self.dbAdapter = FinecoDBAdapter(dbConnection)
    
    def parseQuoteAmount(self,divQuoteSummary,dailyQuote):
        pass
    
    def parseQuoteVariations(self,divQuoteSummary,dailyQuote):
        pass
    
    def parseQuoteUpdateTime(self,divQuoteSummary,dailyQuote):
        pass
    
    def parseCurrency(self,htmlRoot,dailyQuote):
        pass
    
    
    
    def scrape(self):
        # save the db
        stockCodeList = self.dbAdapter.selectStockCodeList()
        listSize = len(stockCodeList)
        
        # prepare the driver
        driver = webdriver.Firefox()
        self.login(driver)
        
        print "There are %s stock codes to process" % listSize
        index = 1
        
        # for every code
        for stockCode in stockCodeList:
            print "[%d/%d] Scraping %s code..." % (index,listSize,stockCode),
            # perform a scrape
            dailyQuote = self.scrapeStockCode(stockCode,driver)
            # update the quotation
            self.dbAdapter.updateQuotation(dailyQuote)
            
            index = index + 1
            print "DONE"
            
        driver.quit()
    
    def login(self,driver):
        
        # open the main page
        driver.get("https://nuovosito.fineco.it/portalelogin")
        
        # display the login pane
        driver.find_element_by_xpath("/html/body/header/div[1]/div/nav/button").click()
        
        time.sleep(1)
        
        # enter username and password
        driver.find_element_by_xpath("//input[@id='user']") #.send_keys()
        driver.find_element_by_xpath("//input[@id='password']") #.send_keys()
        
        # submit the form
        driver.find_element_by_xpath("//form[@id='loginForm']/div[4]/input").click()
        
    
    def scrapeStockCode(self,stockCode,driver):
        dailyQuote = DailyQuote(stockCode,self.SCRAPER_CODE)
        
        driver.get("https://nuovosito.fineco.it/mercati-e-trading/pro/morningstar/it/fetf/SnapshotScheda.aspx?symbol=ISF:AFF")
        
        htmlRoot = BeautifulSoup(driver.page_source,"lxml")
        print htmlRoot.prettify(encoding='utf-8')

        
        return dailyQuote