This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

Node.js 3日目 授業

Last updated at Posted at 2017-01-20

復習振り返り

  • URL
  • querystring
  • module / require
  • ルーティング
  • SQL構文振り返り

今回利用したデータベーステーブルの情報

CREATE TABLE `bbs` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(20) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `content` text,
  `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8;

セキュリティ

  • SQLインジェクション
  • クロスサイトスクリプティング
  • CSRF
  • その他

フレームワーク

API利用、非同期処理

宿題

ジーズアカデミーのメンターの名前一覧を取得する機能を作りましょう。

ヒント

Node.jsでHTTP GETしてJSONパースするメモ

htmlを取得 -> HTMLから情報の抽出という流れになります。

以下でhtmlの取得までができます。

gs_scraping.js
'use strict'

const http = require('http');
const URL = `http://gsacademy.tokyo/mentor/`;

http.get(URL, (res) => {
  let body = '';
  res.setEncoding('utf8');
  res.on('data', (chunk) => {
      body += chunk;
  });
  res.on('end', (res) => {
      console.log(body); //ここでHTMLを取得できる
  });
}).on('error', (e) => {
  console.log(e.message); //エラー時
});
$ node gs_scraping.js
<!DOCTYPE html>
<html lang="ja" xml:lang="ja" prefix="og: http://ogp.me/ns# fb: http://www.facebook.com/2008/fbml">
<head>
・
・(省略)
・

こんな感じでHTMLを取得できます。

などを使ってパースしてみましょう。



完成イメージ

$ node gs_scraping.js
藤川真一
増渕大輔
岡本雄樹
今井智章
石倉 昇
宗定洋平
菅原のびすけ
中農 稔
竹添直樹
斉藤晋介
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