ookla speedtest results
1.0.0
このリポジトリは、JSON形式でOoklaが提示したSpeedTest.NETからインターネット速度テスト結果をスクレイプして取得する方法を提供します。これは、Webサイトから手動で抽出することなく、ダウンロードおよびアップロード速度に関する構造化されたデータを必要とする人にとって役立ちます。
これらの指示では、スクリプトをセットアップして使用して速度テストデータを取得する方法について説明します。
git clone https://github.com/vante-dev/ookla-speedtest-results.git
cd ookla-speedtest-results
npm install axios
or
yarn add axios
スクリプトを使用してOokla速度テストデータをスクレイプするには、以下の例コードに従ってください。この関数Scrapeookladataは、提供されたURLからデータを取得し、ダウンロードを解析し、応答から速度をアップロードします。
import axios from 'axios' ;
async function scrapeOoklaData ( url : string ) {
try {
const res = await axios . get ( url ) ;
const match = res . data . match ( / window.OOKLA.INIT_DATAs*=s*({.*?}); / ) ;
if ( match ) {
const data = JSON . parse ( match [ 1 ] ) ;
return {
download : data . result . download / 1000 , // in Mbps
upload : data . result . download / 1000 , // in Mbps
} ;
}
return {
download : 0 ,
upload : 0 ,
} ;
} catch ( error ) {
return {
download : 0 ,
upload : 0 ,
} ;
}
}
// Example usage:
const url = 'https://www.speedtest.net/result/your-test-id' ;
scrapeOoklaData ( url ) . then ( ( data ) => {
console . log ( 'Download speed:' , data . download , 'Mbps' ) ;
console . log ( 'Upload speed:' , data . upload , 'Mbps' ) ;
} ) ;