How to scrape time-series chart data from poocoin app with Python

0 votes

In trying to get token info from the poocoin.app and although all the other information is available, it is hindering my ability to get time-series data from the chart.

import requests, re 
from bs4 import BeautifulSoup 
import pandas as pd 
url = 'https://poocoin.app/tokens/0x7606267a4bfff2c5010c92924348c3e4221955f2' 
response = requests.get(url) 
soup = BeautifulSoup(response.text, 'html.parser')

Feb 8, 2022 in Python by Soham
• 9,700 points
1,285 views

1 answer to this question.

0 votes

In order to ensure it works, one of the steps you can take is to directly request to their API, to transform it to JSON via the requests .json() decoder, and grab the data you need the same way you would access a dictionary: ["some_key"].

To be aware of where to send the given request, one can follow the given steps:

Dev tools -> Network -> Fetch/XHR -> find name and click on it (in this case: candles-bsc?..) -> Preview (see if response is what you want) -> Headers -> copy Request URL -> make a request -> optional: add additional request headers if response != 200.
 

In order to test a given response, one can use Insomnia. You can use Insomnia to test a response. Search and find the name by following these steps:

Fetch/XHR -> right click -> copy as cURL (bash) -> place inside Insomnia -> see the response.

In order to reach a 200 status code, one must request headers by passing a user-agent.

Pass

User-agent:

headers = { 

"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36", } 

response = requests.get("URL", headers=headers)

The next line of code would be:

 

import requests 
headers = { 
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36", 
} 

params = {
"to":"2021-11-29T09:15:00.000Z",
"limit":"321", 
"lpAddress":"0xd8b6A853095c334aD26621A301379Cc3614f9663", 
"interval":"15m", 
"baseLp":"0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16" 
} 

response = requests.get("https://api2.poocoin.app/candles-bsc", params=params, headers=headers).json() 

# whole response from API call for a particular token (i believe) 
# some data needs to be adjusted (open/close price, etc.)
for result in response: 
count = result["count"] _
time = result["time"] 
open_price = result["open"] 
close_price = result["close"] 
high = result["high"] 
low = result["low"] 
volume = result["volume"] 
base_open = result["baseOpen"] 
base_close = result["baseClose"] 
base_high = result["baseHigh"] 
base_low = result["baseLow"]

print(f"{count}\n"
F"{_time}\n"
F"{open_price}\n"
F"{close_price}\n"
F"{high}\n"
f"{low}\n" 
F"{volume}\n"
F"{base_open}\n"
f"{base_close}\n" 
F"{base_high}\n"
f"{base_low}\n") 

# part of the output: 
''' 
194 
2021-11-29T06:00:00.000Z 
6.6637177e-13 
6.5189422e-13
6.9088173e-13 
5.9996067e-13 
109146241968737.17 
610.0766516756873 
611.1764494818917 
612.3961994618185 
606.7446709385977 

1
2021-11-25T16:15:00.000Z 
1.7132448e-13 
1.7132448e-13 
1.7132448e-13 
1.7132448e-13 
874858231833.1771 
643.611707269882
642.5014860521045 
644.5105804619558 
638.9447353699617

# …
answered Feb 8, 2022 by Rahul
• 9,670 points

Related Questions In Python

0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,090 points
11,145 views
0 votes
1 answer

How to parse date/time string with timezone abbreviated name in Python?

The parse() function in dateutil can't handle ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,560 points
1,910 views
0 votes
1 answer

How to read data from a text file using Python?

Refer to the below example where the ...READ MORE

answered May 13, 2019 in Python by Sushma
1,250 views
0 votes
1 answer

How to call Python script from bash with an agrument?

Hi, You need to call the same command ...READ MORE

answered Jun 25, 2019 in Python by Shabnam
• 930 points
11,519 views
0 votes
1 answer

How to download intext images with beautiful soup

Try this: html_data = """ <td colspan="3"><b>"Assemble under ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 58,090 points
5,133 views
0 votes
1 answer

How to download intext images with beautiful soup

Ohh... I got what you need. Try this: html_data ...READ MORE

answered Sep 20, 2018 in Python by Priyaj
• 58,090 points
5,372 views
0 votes
1 answer

How to use BeautifulSoup for Webscraping

Your code is good until you get ...READ MORE

answered Sep 6, 2018 in Python by Priyaj
• 58,090 points
1,929 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,090 points
1,436 views
0 votes
3 answers

'python' is not recognized as an internal or external command

Try "py" instead of "python" from command line: C:\Users\Cpsa>py Python 3.4.1 (v3.4.1:c0e311e010fc, May ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
2,064 views
0 votes
1 answer

Reverse a string in Python

You should try to use the following ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
478 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP