The value you're trying to scrape - the total ICX balance - appears to be the sum of the "available" ICX, and the "staked" ICX:
I've added the red lines for emphasis. The sum of these two values is the total ICX balance. Again, if you log your browser's network traffic, you'll find that these values come from requests made to different REST APIs. One is a HTTP GET request, the other an HTTP POST request. Again, you can find out how the POST payload is supposed to look by looking at the network traffic logs. If you need a little guidance for how to approach these kinds of network-traffic-sniffing solutions, I recommend you read this answer I posted for a different question, where someone needed help scraping information from a page about different wines and vineyards, and that page also happened to make XHR requests to a REST API. In it, I go more in-depth about each step of logging your network traffic, and finding the information you're looking for.
def get_available_icx(address):
import requests
url = "https://tracker.icon.foundation/v3/address/info"
params = {
"address": address
}
response = requests.get(url, params=params)
response.raise_for_status()
return float(response.json()["data"]["balance"])
def get_staked_icx(address):
import requests
url = "https://wallet.icon.foundation/api/v3"
form_data = {
"jsonrpc": "2.0",
"id": 0,
"method": "icx_call",
"params": {
"from": "hx0000000000000000000000000000000000000000",
"to": "cx0000000000000000000000000000000000000000",
"dataType": "call",
"data": {
"method": "getDelegation",
"params": {
"address": address
}
}
}
}
response = requests.post(url, json=form_data)
response.raise_for_status()
return int(response.json()["result"]["totalDelegated"], 16) / (10 ** 18)
def main():
address = "hx4ae18d8f72200dc564673a0ae7206d862992753c"
total_icx = get_available_icx(address) + get_staked_icx(address)
print(total_icx)
return 0
if __name__ == "__main__":
import sys
sys.exit(main())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…