Exemplo n.º 1
0
 def getHistoryData(self, currencyCode):
     historyUrl = "http://srh.bankofchina.com/search/whpj/search.jsp"
     data_list = []
     date = datetime(2016, 1, 1).date()
     while date < datetime.today().date():
         r = requests.post(
             historyUrl,
             data={
                 "erectDate": str(date),
                 "nothing": str(date),
                 "pjname": BOCPriceSearcher.curencyDic[currencyCode]["num"]
             })
         soup = BeautifulSoup(r.text, 'html5lib')
         soup = soup.find_all("table")[1]
         tds = soup.find_all("tr")[1].find_all("td")
         data = CurrencyRate(
             "BOC", currencyCode,
             tds[4].contents[0] if len(tds[4].contents) != 0 else 0,
             tds[2].contents[0] if len(tds[2].contents) != 0 else 0,
             datetime.strptime(tds[7].contents[0],
                               "%Y.%m.%d %H:%M:%S").date())
         print(str(data))
         data_list.append(data)
         date = date + timedelta(days=1)
     return data_list
    def getData(self):

        r = requests.post(self.url)
        #r.encoding
        result = r.json()["data"]["currencyList"]
        data_list = []
        for item in result:
            data_list.append(
                CurrencyRate("ctrip", item["currencyCode"], item["sellPrice"],
                             item["buyPrice"]))
        print(data_list)
        return data_list
Exemplo n.º 3
0
 def getData(self):
     r=requests.get("http://fx.cmbchina.com/hq/")
     r=re.search('[\s]{1}<table cellpadding="0" cellspacing="1" width="740" align="center" class="data">[\s\S]*</table>[\s]{1}',r.text)
     soup=BeautifulSoup(r.group(),'html5lib')
     data_list=[]
     for idx,tr in enumerate(soup.find_all("tr")):
         if idx!=0:
             tds=tr.find_all("td")
             data_list.append(CurrencyRate(
                 "CMB",
                 CMBPriceSearcher.curencyDic[getCleanStr(tds[0].contents[0])],
                 getCleanStr(tds[4].contents[0]),
                 getCleanStr(tds[6].contents[0])))
     return data_list
Exemplo n.º 4
0
 def getHistoryData(self,currencyCode):
     historyUrl="http://buy.travelex.com.cn/zhcn/RateChart?Profile=online&ProductType=Cash&foreignCurrency=%s" % currencyCode
     data_list=[]
     r=requests.get(historyUrl)
     r=re.search("\(\[\[[\s\S]*\]\]\)",r.text)
     source=r.group().replace("([","").replace("])","")
     source=re.findall("\[[\d]+,[\d|.]+\]",source)
     result=[x.replace("[","").replace("]","").split(",") for x in source]
     for item in result:
         c=CurrencyRate(
             "Travelex",
             currencyCode,
             float(item[1])*(100/TravelexPriceSearcher.curencyDic[currencyCode]),
             0,
             datetime.fromtimestamp(int(item[0].replace("00000","00"))))
         print(c)
         data_list.append(c)                   
     return data_list
Exemplo n.º 5
0
 def getHistoryData(self,currencyCHNName):
     historyUrl="http://fx.cmbchina.com/Hq/History.aspx?&nbr=%s&page=" % currencyCHNName
     data_list=[]
     for pageID in range(1,20):
         r=requests.get(historyUrl+str(pageID))
         r=re.search('</tbody>[\s]+<tbody>[\s\S]*</tr>[\s]+</tbody>',r.text)
         soup=BeautifulSoup("<table>"+r.group()+"</table>",'html5lib')
         
         for tr in soup.find_all("tr"):
             tds=tr.find_all("td")
             data=CurrencyRate(
                 "CMB",
                 CMBPriceSearcher.curencyDic[currencyCHNName],
                 getCleanStr(tds[4].contents[0]),
                 getCleanStr(tds[2].contents[0]),
                 getDateTime(getCleanStr(tds[0].contents[0])))
             print(str(data))
             data_list.append(data)   
     return data_list