-1

I'm trying to fetch this page on Linux, in a bash script: https://www.worldcoinindex.com/coin/siacoin

When it's firstly explored on browser, it shows off Siacoin's prices in USD. On the page there's a drop-down menu that you can use to select in which currency you'd like to see the current currency prices. I'd like to fetch Siacoin's prices in BTC. After a few research I was able to find the form id, tn_q and ended up with the following command:

curl --silent -d tn_q="BTC" --connect-timeout 2 https://www.worldcoinindex.com/coin/siacoin |html2text|grep siacoin|grep SC|head -n1| awk '{ print $4 }'

But it fails to show what I'm looking for, it still shows price in USD.

I'm lost, as the URL of the site won't change when you set the expected value from the drop-down, and I don't know how to tell curl to set this field for me.

Edit #1:

I tried the cookie way, with no success. Found the following cookie on my Chrome, but still getting USD price.

curl --silent --cookie "WCI-CURRENCY=btc" --connect-timeout 2 https://www.worldcoinindex.com/coin/siacoin |html2text|grep siacoin|grep SC|head -n1| awk '{ print $4 }'
  • I've worked around this using other sites APIs for getting the coins prices in JSON and then parsing with jq -r in order to get them working as variables in my bash script. – Marco Aug 15 '17 at 21:36
  • 1
    I don't know why, but your "edit" version with cookie works fine for me. Maybe because i previously used lynx https://www.worldcoinindex.com/coin/siacoin to access the web page and i accepted manually all the cookies; this is a lynx procedure that is not automatically storing all the cookies but user confirmation is required. – George Vasiliou Aug 15 '17 at 21:44
  • 2
    After your comment I tried with wget --save-cookies and then wget --load-cookies after editing the cookie file and it worked! – Marco Aug 15 '17 at 21:59
  • Great! By the way i noticed that this particular cookie expires in 24 hours.... Maybe this can be changed (if editable) in 24 years :) – George Vasiliou Aug 15 '17 at 22:02
  • Of course I was checking for testing purposes, each of the sites where Worldcoinindex takes prices from support public APIs, so the best way to take coin prices from to use as variables in the script is by far from each site's JSON, parsed with "jq -r" and I'm already developing the script with this new approach. – Marco Aug 15 '17 at 22:06
1

A decent web browser debugger will allow you to discover that the currency is set as a cookie.

curl --silent --cookie WCI-CURRENCY=btc --connect-timeout 2 https://www.worldcoinindex.com/coin/siacoin |
    tee siacoin.html |
    html2text |
    tee siacoin.txt |
    grep SC

[Siacoin] siacoin SC    0.00000169 %      0.00000178  0.00000161 1,429  14,050,000,000 23,745
****** siacoin SC ******
****** siacoin SC ******
Poloniex      SC/BTC 0.00000170  700
Bittrex       SC/BTC 0.00000169  466
Yunbi         SC/CNY 0.00000164  264
Total/Average SC/BTC 0.00000169  1,429

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.