我正在嘗試從 poocoin 中獲取令牌資訊。所有其他資訊都可用,但我無法從圖表中抓取時間序列資料。
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')
uj5u.com熱心網友回復:
您可以通過向他們的 API 發出直接請求(我相信)來使其作業,通過requests .json()decoder將其轉換為JSON ,并以與訪問字典相同的方式獲取您需要的資料:["some_key"]。
定位發送請求的位置:(Dev tools -> Network -> Fetch/XHR -> find name and click on it在本例中:candles-bsc?..)-> Preview(看看回應是否是您想要的)-> Headers -> copy Request URL -> make a request -> optional: add additional request headers if response != 200。
您可以使用Insomnia 來測驗回應。在 下查找名稱Fetch/XHR -> right click -> copy as cURL (bash) -> place inside Insomnia -> see the reponse。
在這種情況下,你只需要傳遞一個user-agentto requestheaders就可以收到一個200狀態碼,否則會拋出一個403or503狀態碼。檢查你的user-agent.
通過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)
在線IDE中的代碼和示例:
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
# ...
'''
PS 我有一個專門的網路抓取博客。每當需要決議搜索引擎時,請查看SerpApi。
免責宣告,我為 SerpApi 作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/369461.html
