Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I return a figure when scraping html page?

I am trying to extract the 24hr Volumes from this page. They have an API except it seems as though volume isn’t returned in the json data (at least I can’t get it to work). I have tried simple scraping using regex and am now using the lxml xpath methond.

What can I do to get the 24hr volume from this page?? Is it protected?

This is my latest code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from lxml import html
import requests

swyftx_page = requests.get('https://swyftx.com/au/buy/bitcoin/')
swyftx_tree = html.fromstring(swyftx_page.content)
swyftx_prices_btc = swyftx_tree.xpath('/html/body/section[1]/div/div[2]/div/div[2]/div[2]/div[3]/h3/text()')
print(swyftx_prices_btc)

When I run this, I get:

['$0.00']

Which is obviously not right. I am expecting an answer like:

['34,560,324,200']

>Solution :

The data you see on the page is loaded from external URL via JavaScript. To simulate it via requests module, you can use this example:

import json
import requests


url = "https://apic.swyftx.io/markets/aud/"

data = requests.get(url).json()

# uncomment to print all data:
# print(json.dumps(data, indent=4))


for d in data:
    if d["name"] == "Bitcoin":
        print("Volume:", d["volume24H"])
        break

Prints:

Volume: 34974203469
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading