Skip to content

Instantly share code, notes, and snippets.

@afrontend
Last active July 20, 2017 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afrontend/83dfd04002fc7f57b34a11fb85f06f19 to your computer and use it in GitHub Desktop.
Save afrontend/83dfd04002fc7f57b34a11fb85f06f19 to your computer and use it in GitHub Desktop.
서울의 현재 기온을 표시하는 자바스크립트를 생성하는 bash 스크립트, https://agvim.wordpress.com/2017/07/06/reading-web-data-using-javascript-in-node-js/
#!/usr/bin/env bash
# Filename: temperature.sh
command -v npm >/dev/null 2>&1 || { echo >&2 "I require npm but it's not installed. Aborting."; exit 1; }
command -v node >/dev/null 2>&1 || { echo >&2 "I require node but it's not installed. Aborting."; exit 1; }
cd /tmp
npm install request cheerio
cat > temperature.js << "EOF"
var request = require('request');
request('https://www.accuweather.com/ko/kr/seoul/226081/weather-forecast/226081',
function (error, response, body) {
const cheerio = require('cheerio')
const $ = cheerio.load(body);
console.log($('#current-city-tab > a > span.local-temp').text());
});
EOF
node temperature.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment