[Python] 内部取引所のマーケットを取得してみる

こんにちは、@yasuです。

内部取引所のマーケットを取得してみました。
https://steemitwallet.com/market

少し長いですが、結果を見やすくすためのprintが多いからです。
steemitwallet.com/marketのページからタグ名やクラス名をもとに該当の値を見つけています^^

動作環境

以下の投稿を参考にしてください。

コード

#
# 内部取引所のオーダーを表示する
#

from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def steemit_market():
    
    url = "https://steemitwallet.com/market"
    browser = webdriver.Chrome()
    browser.get(url)

    SELLSIZE = 13

    #買いと売りの2つのテーブルあり。
    elems = browser.find_elements_by_class_name("Market__orderbook")

    #
    # 買い注文
    #

    elem = elems[0]
    #タイトル
    rows = elem.find_element_by_tag_name("thead").find_elements_by_tag_name("tr")
    for row in rows:
        cells = row.find_elements_by_tag_name("th")
        #Total SBD ($)       SBD ($)         Steem         price
        print(f"{cells[0].text.replace('가격','price').rjust(SELLSIZE)} {cells[1].text.rjust(SELLSIZE)} {cells[2].text.rjust(SELLSIZE)} {cells[3].text.replace('가격','price').rjust(SELLSIZE)}")
        #-------------+-------------+-------------+-------------
        print(f"{'-'*SELLSIZE}+{'-'*SELLSIZE}+{'-'*SELLSIZE}+{'-'*SELLSIZE}" )
    #データ
    rows = WebDriverWait(elem, 5).until(lambda x: x.find_element_by_tag_name("tbody").find_elements_by_tag_name("tr"))
    for row in rows:
        cells = row.find_elements_by_tag_name("td")
        print(f"{cells[0].text.rjust(SELLSIZE)} {cells[1].text.rjust(SELLSIZE)} {cells[2].text.rjust(SELLSIZE)} {cells[3].text.rjust(SELLSIZE)}")
    print()

    #
    # 売り注文
    #

    elem = elems[1]
    #タイトル
    rows = elem.find_element_by_tag_name("thead").find_elements_by_tag_name("tr")
    for row in rows:
        cells = row.find_elements_by_tag_name("th")
        #        price         Steem       SBD ($) Total SBD ($)
        print(f"{cells[0].text.replace('가격','price').rjust(SELLSIZE)} {cells[1].text.rjust(SELLSIZE)} {cells[2].text.rjust(SELLSIZE)} {cells[3].text.replace('가격','price').rjust(SELLSIZE)}")
        #-------------+-------------+-------------+-------------
        print(f"{'-'*SELLSIZE}+{'-'*SELLSIZE}+{'-'*SELLSIZE}+{'-'*SELLSIZE}" )
    #データ
    rows = WebDriverWait(elem, 5).until(lambda x: x.find_element_by_tag_name("tbody").find_elements_by_tag_name("tr"))
    for row in rows:
        cells = row.find_elements_by_tag_name("td")
        print(f"{cells[0].text.rjust(SELLSIZE)} {cells[1].text.rjust(SELLSIZE)} {cells[2].text.rjust(SELLSIZE)} {cells[3].text.rjust(SELLSIZE)}")


steemit_market()

実行結果

image.png

スクリーンショット

内部取引所のマーケット部分です。

image.png

Coin Marketplace

STEEM 0.12
TRX 0.34
JST 0.033
BTC 122177.64
ETH 4487.88
SBD 0.79