Simple cryptocurrency scrapper

Bitcoin and all cryptocurrencies are trendy and extremely volatile. It's difficult to follow all movements, changes and drops. In order to follow some of them I did a simple script. This script is getting information from several sites and record the date and the price. Below you can find a version for: coinmarketcap. You can customized it on your needs.

Basically I have 50 snapshots per day. This give good picture, saves me time and avoid emotional decisions. I'm also training small neural network in guessing the bitcoin direction. Deep learning show some advantages in discovering next "crypto gold" and finding the losers. I did also a small trader bot - bitcoin bot - which is using this data. So far the result of this crypto bot is not clear - is it working or the markets are rising up.

Simple cryptocurrency scrapper

@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')

def parser = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())

def page = parser.parse('https://coinmarketcap.com/')

def listName = []
def listPrice = []
def listPercent = []

page.depthFirst().collect { it }.findAll { it.name() == "a" && it.@class == "currency-name-container" }.each {
   println "${it.text()}"
   listName << it.text()
}


page.depthFirst().collect { it }.findAll { it.name() == "a" && it.@class == "price" }.each {
   println "${it.text()}"
   listPrice << it.text()
}

page.depthFirst().collect { it }.findAll { it.name() == "td" && it.@class.toString().contains("percent-24h") }.each {
   println "${it.text()}"
   listPercent << it.text()
}


listName.eachWithIndex{name, index->
    println "name: ${name},     price: ${listPrice[index]},     percent: ${listPercent[index]} "
}

Result

name: Bitcoin,     price: $7042.88,     percent: 8.41% 
name: Ethereum,     price: $282.97,     percent: -6.68% 
name: Bitcoin Cash,     price: $566.12,     percent: 15.91% 
name: Ripple,     price: $0.186956,     percent: -6.68% 
name: Litecoin,     price: $51.50,     percent: -7.25% 
name: Dash,     price: $256.34,     percent: -7.94% 
name: BitConnect,     price: $261.19,     percent: 8.29% 
name: NEO,     price: $24.71,     percent: -9.57%

Related Article