Python爬蟲--爬取非小號中虛擬幣的價格

#coding=utf-8

import requests,random
from bs4 import BeautifulSoup
import sys,datetime,time
from xlrd import open_workbook
from xlutils.copy import copy
import xlrd,xlwt

reload(sys)
sys.setdefaultencoding('utf-8')


class Fire:

    global i

    def __init__(self):
        self.headers_1 = {      # ADA/USDT請求頭信息
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding':'gzip, deflate, br',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Cookie':'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525403401; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525405335; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525409964',
            'Host':'www.feixiaohao.com',
            'Upgrade-Insecure-Requests':'1'
        }

        self.headers_2 = {      # EOS/USDT請求頭信息
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding':'gzip, deflate, br',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Cookie':'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525403401; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525416135; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525419382',
            'Host':'www.feixiaohao.com',
            'Upgrade-Insecure-Requests':'1'
        }

        self.headers_3 = {
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding':'gzip, deflate, br',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Cookie':'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525403401; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525428845; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525431281',
            'Host':'www.feixiaohao.com',
            'Upgrade-Insecure-Requests':'1'
        }

        self.headers_4 = {
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding':'gzip, deflate, br',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Cookie':'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525403401; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525428845; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525431460',
            'Host':'www.feixiaohao.com',
            'Upgrade-Insecure-Requests':'1'
        }

        self.headers_6 = {      # WICC/BTC請求頭信息
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding':'gzip, deflate, br',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Cookie':'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662535,1525662540,1525754228,1525754968; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525754968',
            'Host':'www.feixiaohao.com',
            'Upgrade-Insecure-Requests':'1'
        }

        self.headers_7 = {  # APPC/BTC請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525755161',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }

        self.headers_8 = {  # SNT/BTC請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525755543',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }

        self.headers_10 = {  # REQ/BTC請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525755820',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }

        self.headers_11 = {  # MTN/BTC請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525756173',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }

        self.headers_12 = {  # MTN/BTC請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525757054',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }

        self.headers_13 = {  # BCH/USDT請求頭信息
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'UM_distinctid=1632920ba7831d-08796d23010447-7e5a600d-ff000-1632920ba7928d; usid=39af3e641c8f2ace; CNZZDATA1263003344=1945603078-1525399934-%7C1525754408; Hm_lvt_192e611c7ffa4b2f8a5047e5cf45403f=1525662540,1525754228,1525754968,1525754983; Hm_lpvt_192e611c7ffa4b2f8a5047e5cf45403f=1525757637',
            'Host': 'www.feixiaohao.com',
            'Upgrade-Insecure-Requests': '1'
        }


        self.proxy_list = [  # 設置代理
            {'http': '202.117.120.242:8080'},  #
            {'http': '113.200.214.164:9999'},  #
            {'http': '27.46.5.97:9797'},  #
            {'http': '113.200.214.164:9999'},  #
            {'http': '42.157.5.154:9999'},  #
            {'http': '113.118.96.46:9797'},  #
            {'http': '210.26.125.142:8080'},  #
        ]
        self.proxy = random.choice(self.proxy_list)

#ADA/USDT 火幣pro
    def test_messageADA_G(self):     # 獲取想要得到的數據:幣種交易平臺、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/cardano/',headers=self.headers_1)     #發送請求並獲得返回數據
        #print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text,'lxml')    #使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-usd']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-5:-1] == "USDT":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')   # 打開想要更改的excel文件
                new_excel = copy(old_excel)    # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)   # 獲取第一個sheet
                ws.write(1,1,price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環



# EOS/USDT  火幣pro
    def test_messageEOS_G(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/eos/',
                               headers=self.headers_2)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]     #去掉第一個不正確的msg標籤信息
        for info in adress:     #遍歷所有數據的信息
            name = info.find('img')['alt']     # 獲取交易平臺的信息
            price = info.find('td',class_='price')['data-usd']     # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-5:-1] == "USDT":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')   # 打開想要更改的excel文件
                new_excel = copy(old_excel)    # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)   # 獲取第一個sheet
                ws.write(2,1,price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break     # 正確存取之後跳出for循環

# AST/BTC 火幣pro平臺
    def test_messageAST_G(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/airswap/',
                               headers=self.headers_3)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')   # 打開想要更改的excel文件
                new_excel = copy(old_excel)    # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)   # 獲取第一個sheet
                ws.write(3,1,price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環


# BFT/BTC 火幣pro平臺
    def test_messageBFT_G(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/bnktothefuture/',
                               headers=self.headers_4)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')   # 打開想要更改的excel文件
                new_excel = copy(old_excel)    # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)   # 獲取第一個sheet
                ws.write(4,1,price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環


# 寶寶的幣

# WICC/BTC 火幣pro平臺
    def test_messageWICC_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/waykichain/',
                               headers=self.headers_6)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')   # 打開想要更改的excel文件
                new_excel = copy(old_excel)    # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)   # 獲取第一個sheet
                ws.write(6,1,price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# APPC/BTC 火幣pro平臺
    def test_messageAPPC_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/appcoins/',
                               headers=self.headers_7)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(7, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# SNT/USDT 火幣pro平臺
    def test_messageSNT_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/status/',
                               headers=self.headers_8)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-usd']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-5:-1] == "USDT":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(8, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環
        #SNT/BTC)
        for info1 in adress:  # 遍歷所有數據的信息
            name = info1.find('img')['alt']  # 獲取交易平臺的信息
            price = info1.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info1.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(9, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# REQ/BTC 火幣pro平臺
    def test_messageREQ_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/request-network/',
                               headers=self.headers_10)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(10, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# MTN/BTC 火幣pro平臺
    def test_messageMTN_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/medical-chain/',
                               headers=self.headers_11)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中
                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(11, 1, price)
                ws.write(12, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# BTM/BTC 火幣pro平臺
    def test_messageBTM_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/bytom/',
                               headers=self.headers_12)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all('tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-btc']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-4:-1] == "BTC":  # 當所得到的交易平臺正確時,將數據存入excel中                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(13, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環

# BCH/USDT 火幣pro平臺
    def test_messageBCH_B(self):  # 獲取想要得到的數據:幣種交易平臺名稱、當前價格、當前時間
        result = requests.post('https://www.feixiaohao.com/currencies/bitcoin-cash/',
                               headers=self.headers_13)  # 發送請求並獲得返回數據
        # print result.content     #打印返回的數據信息
        result_soup = BeautifulSoup(result.text, 'lxml')  # 使用BeautifulSoup來解析我們獲取到的網頁(‘lxml’是指定的解析器
        adress = result_soup.find('table', class_='table3 tableMaxWidth').find_all(
            'tr')  # 查找該class下的table標籤,然後再找到裏面所有的tr標籤
        del adress[0]  # 去掉第一個不正確的msg標籤信息
        for info in adress:  # 遍歷所有數據的信息
            name = info.find('img')['alt']  # 獲取交易平臺的信息
            price = info.find('td', class_='price')['data-usd']  # 獲取該交易平臺該幣種的金額
            jiaoyidui = info.find_all('td')[2].get_text()
            if name == "火幣Pro-Huobi" and jiaoyidui[-5:-1] == "USDT":  # 當所得到的交易平臺正確時,將數據存入excel中                # 將數據寫入excel中
                old_excel = xlrd.open_workbook('Original.xls')  # 打開想要更改的excel文件
                new_excel = copy(old_excel)  # 將操作文件對象拷貝,變成可寫的workbook對象
                ws = new_excel.get_sheet(0)  # 獲取第一個sheet
                ws.write(14, 1, price)
                new_excel.save('Original.xls')
                print ""+jiaoyidui+" = "+price+""
                break  # 正確存取之後跳出for循環


if __name__ == "__main__":
    m = Fire()
    m.test_messageADA_G()
    m.test_messageEOS_G()
    m.test_messageAST_G()
    m.test_messageBFT_G()

    m.test_messageWICC_B()
    m.test_messageAPPC_B()
    m.test_messageSNT_B()
    m.test_messageREQ_B()
    m.test_messageMTN_B()
    m.test_messageBTM_B()
    m.test_messageBCH_B()
    ```
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章