Home > database >  Python: request url and get contents
Python: request url and get contents

Time:12-02

I am trying to get transaction history for the following address 9QgXqrgdbVU8KcpfskqJpAXKzbaYQJecgMAruSWoXDkM from the https://explorer.solana.com website.

I have tried

url="https://explorer.solana.com/address/9QgXqrgdbVU8KcpfskqJpAXKzbaYQJecgMAruSWoXDkM"
output = requests.get(url).text
print(output)

However this gives me raw html output.

How can I get the transactions from the url?

CodePudding user response:

The history data is loaded from external URL via JavaScript. You can use requests module to simulate this call:

import requests
import pandas as pd


api_url = "https://explorer-api.mainnet-beta.solana.com/"

payload = {
    "id": "xxx",
    "jsonrpc": "2.0",
    "method": "getConfirmedSignaturesForAddress2",
    "params": ["9QgXqrgdbVU8KcpfskqJpAXKzbaYQJecgMAruSWoXDkM", {"limit": 25}],
}

data = requests.post(api_url, json=payload).json()

df = pd.DataFrame(data["result"])
df["blockTime"] = pd.to_datetime(df["blockTime"], unit="s")

print(df.to_markdown(index=False))

Prints:

blockTime confirmationStatus err memo signature slot
2022-11-30 12:36:01 finalized 4Pb3aMuiNGx1Xavj5GyeZHKAWvDp1BJAYXS3s1JjTx7uRr2qGNLGMkgPvicvMJGvKdt7gC5hTcDA822qu4th1MvR 164077374
2022-11-23 13:05:04 finalized 5vWbZozXwTmNeqCwLDu8pgLKhf8gSbyAVuHamzDMGh3amYjtYZ5V647wkDigYQ4aRnSKNGNGzYYPtksHgYBeuF1b 162708675
2022-10-17 17:37:48 finalized 2wYEAAZPBPu1ropcTV4k78BB6FbemhAQmnSRvRcuLHVz9j3Kh5tufMokJ5j3JsCsL8vRArUa3HtYP67bgNGJdLGk 155859139
2022-09-18 09:34:45 finalized [209] Please consider to delegate with ManyStake in order to decentralize the solana network. OG delegator will be rewarded soon with extra MEV rewards. Our vote account AuBB9st3RqhHBkzZgBSm6SVnHZNJQSHeBWCSkik4bzdA 48r1hcNHn4vw9kzd7fJnj4HWrLqzSsDfn6Ap6Dpbb2qwj6WL1xbYmah1CifVVBhwDZDqg6fsmUHqHW9t3m454pX8 151207313
2022-06-19 18:35:55 finalized 5v7T4aYM6dN9SK3V7Y6VS59aBcWabyNdyxLLJuKecZrTt2VqT1kW6MHobYxjGv4DHb8SYewB3Y1ZNhWML2pCFCGL 138178511
2022-06-19 18:33:24 finalized 2ULTeYi3tqZi9xDtnPnNPYjYRGt8a8EcoAxZG2uGNkHvrNWiF3evbcSPmxN3LvGU9g1j8n9KYVqRmtzLTwhWfhr7 138178280
2022-06-19 18:19:04 finalized 4YnvsFtHPGzgijPB7KPEsBqj4o1ZigimhiPFuoyrCv8NLivVipNFp6RTmsNhkoeCYeDhWcK3ovkCqMmjYfQj711V 138176965
2022-06-19 18:15:55 finalized EVTjZVQYghRK4bdMwCh6PnazRXZgSjCWvgu6XMqAiaEverkTNtkpfw2E7sRXPe973n1LnzmRnepNkCggLxZZS9S 138176698
2022-06-19 17:55:54 finalized 2P9nSaGMfs2Daks9kGEnUp3R9UNpLZMFTudAjaVgDHJcwwxp1vDgfsn582bZb7HoDJTCrKCkBd3srcuUfXYAH1Tr 138174836
2022-06-19 17:41:14 finalized 3Y7bmsHo3fTD3fqryPy37u6MMDGs9KGk7MLFbxw8sDx15j2sDPtRd4w8QjWWCoecLQQZHMT37Evt4D2oX1wd2sL 138173447
2022-06-19 17:40:46 finalized 2ftBbaqKrMintETRxhH17HvDjEgX5W437BKZv8o4umeNXcs2B9WQJEm9kJEh2LfNeQMCgMkjDZXz8DziLMKvtHk3 138173398
2022-06-19 17:38:41 finalized 7Bdy3Ah78NmRmpbFsmKtFPiqrQGDpXZ2BBr83crivSso7wwbfVzEv4TrdpurYXWJV6X9j9hKfAvLWB3769GobJA 138173207
2022-06-19 17:35:41 finalized 61iQ9BSQ18X54nT2ZzRCUtoUyXpTKS363QZFnXBgERAtUzLscpmj8oxTfrgxn7zwemNEKf1WB2yLhn3JgfmG96MY 138172922
2022-06-19 17:32:16 finalized 5ueuPr4qZwHxhDSWRQHZkrNpTSDa6fR9LiGyokFJ1que6rpgRaSt9AX2S7L89KLztWKmehHKwxDpQywbvXbk6WQB 138172617
2022-06-19 17:26:27 finalized EHRyD9ibJkt6cGgHbKbJqTuBj7bCzxeWGLBwuC8TgucvfKgv3ejqCRkG6sqUDVxQvsRWdGkQpagojRo2vajfDBa 138172080
2022-06-19 17:25:59 finalized 3XxSXVQCKpZH48upHzYSj4nJyhWw6gpPiA6vPW8JyWwfniCh2Z29qokxQi2mtjyUiEWqthix6LKNBRpJhAQb2u8v 138172029
2022-06-19 17:25:46 finalized 3DjUK7ENHYQLWGQ1Rw3bMqCjuzt4M6H1aPxWMVAU37vr2r64F2wXFgFsyeXqSiQ7JA1biQY691iwoEKDj5iztzg6 138172003
2022-06-19 17:25:14 finalized gQwiKLCuvvGDoEoniU6QR98PHTAMDyz7DVbxaYXRYWsPaC7Ekbyt9PDEpDNo7kueSddiN6V1jrwYoN3Rfir3x8w 138171956
2022-06-19 17:22:02 finalized 52dFWxTaKL2h1MekafD12F3QWmnrDbsTxwEAMbZyiDhVNy7miVbwxX5d8NU7WioQpotG4uJ4txoFRRe2irRBqBfh 138171653
2022-06-19 17:21:32 finalized 5yGwSWUZiaY5xAeSy5BFekJoSF3YiPiYh6GC5hyaPCDDQ3WEXWr9EzqWCf1g47ViUHekEMrsRDWuS8XN3k52hFVf 138171595
2022-06-19 17:20:58 finalized 7SkpAQ1JNQYTUvR545pyWBQeHGEpisbgYxsUr1B2fnZm95CmGXUF4Y2UMVQbL1gbtd1mKaTTVCY3RBBpWcchaLD 138171541
2022-06-19 17:20:38 finalized rsYUWj8irRFk15VxkFnjcJChDGyCmpe4MrCgrAyqt9ZoXoUcQsz7wiUKWYaU9qbds7V69jDxxhxbSzSJneJsfzA 138171506
2022-06-19 17:20:12 finalized 4hjqfREeb22rSSuwHAZ5U3g2qZXVi4ejahZxBN95ecjfV3we1ELWP1ezJsCCaSnj9zygzzhWJrzZRpCHB3Nfcnw1 138171464
2022-06-19 17:09:47 finalized 2TXf2fwsYfCCTrkh4zfZSGhbEuZcLrKPwn8Ai4ZTpntKFS6FDU9YahRuT5cEYqYc1RJ5fMMkUtYtcbNv8ogAzVnM 138170550
2022-06-19 17:09:31 finalized wDMRYiqHPNtYy6WJuA1kyaWjLr7RsnemnasEYufpaxdCmroNW4dBFLPLCQnYDnyZha9uZUSgbhC91zQT3E55bpP 138170527
  • Related