LoginSignup
2
1

More than 3 years have passed since last update.

Node.jsにて為替情報を取得

Posted at

中華人民元を日本円で換算したらいくらになっているのかをスクレイピングで取得する

scraping.js
import * as request from 'request';
import * as client from 'cheerio-httpcli'

export function getNowGenValue():number {
    const url = 'https://jp.investing.com/currencies/cny-jpy';
    let urlRes = client.fetchSync(url) // 受け取った値をカスタマイズしてresposeとして返すために同期処理にする
    return parseInt(urlRes.$("#last_last").text());
}

質は有料のものよりも劣るかもだけど、割と爆速で取得できる。
非同期処理にしてもいいかもだけど取得できてなかったらだるいので同期処理にした。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1