java で ipv4 ipv6 を扱う
ipv4
Maven Repository: commons-net » commons-net
ipv6
自前でやるなら
IPv6 Essentials: Integrating IPv6 into Your IPv4 Network
- 作者: Silvia Hagen
- 出版社/メーカー: O'Reilly Media
- 発売日: 2014/06/09
- メディア: Kindle版
- この商品を含むブログを見る
マイクロサービスに於ける認証
JWTのユースケース
の部分を参考
Webを支える技術 -HTTP、URI、HTML、そしてREST (WEB+DB PRESS plus)
- 作者: 山本陽平
- 出版社/メーカー: 技術評論社
- 発売日: 2010/04/08
- メディア: 単行本(ソフトカバー)
- 購入: 143人 クリック: 4,320回
- この商品を含むブログ (182件) を見る
nightmare and daydream
nightmare の スクリプトを生成してくれるやつらしい
初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発
- 作者: Ethan Brown,武舎広幸,武舎るみ
- 出版社/メーカー: オライリージャパン
- 発売日: 2017/01/20
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
nightmare.js を使って Qiita の人気の投稿 の href一覧 を取得する
nightmare.js
一覧を取得する
サンプルをちょっと変えて
.evaluate(function () { return document.querySelector('#main .searchCenterMiddle li a').href })
querySelector
を querySelectorAll
に変えてやればOKでしょとか思ったのになぜか return が null になって困った・・・
javascriptはあまり良くわからないし・・・
.evaluate(function () { return document.querySelectorAll('.popularItem_articleTitle_text').href })
ぐぐってみると以下の記事がヒットしたので少し書き直してみたらうまく行った
.evaluate(function(){ return Array.from(document.querySelectorAll(".popularItem_articleTitle_text"), e => {return e.href;}) })
コード
var Nightmare = require('nightmare'); var nightmare = Nightmare({ show: true }) var qiita_popular_item = 'http://qiita.com/popular-items'; nightmare .goto(qiita_popular_item) .evaluate(function(){ return Array.from(document.querySelectorAll(".popularItem_articleTitle_text"), e => {return e.href;}) }) .end() .then(function (result) { console.log('result', result) }) .catch(function (error) { console.error('Search failed:', error); });
初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発
- 作者: Ethan Brown,武舎広幸,武舎るみ
- 出版社/メーカー: オライリージャパン
- 発売日: 2017/01/20
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
go言語でGETしたresponseをparseする
共通定義
import ( "net/http" "encoding/json" "log" ) func get(client *http.Client, url string, accessToken string, typedef interface{}) interface{} { req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", accessToken) resp, _ := client.Do(req) error := json.NewDecoder(resp.Body).Decode(&typedef) if error != nil { log.Fatal(error) } return typedef }
実際の処理
func fetchCategories(client *http.Client, accessToken string) { url := "https://cloud.feedly.com/v3/categories" var cat []Category get(client, url, accessToken, &cat) for i, m := range cat { fmt.Println(i, m) } }
- 作者: 松木雅幸,mattn,藤原俊一郎,中島大一,牧大輔,鈴木健太,稲葉貴洋
- 出版社/メーカー: 技術評論社
- 発売日: 2016/09/09
- メディア: 大型本
- この商品を含むブログ (2件) を見る
go言語のjsonのパースでちょっとハマったこと
jsonをパースしても [] になってしまう
type Category struct { id string label string } func fetchCategories(client *http.Client, accessToken string) { url := "https://cloud.feedly.com/v3/categories" req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", accessToken) resp, _ := client.Do(req) var cat []Category error := json.NewDecoder(resp.Body).Decode(&cat) if error != nil { log.Fatal(error) } fmt.Println("----------------") fmt.Println(cat) }
原因は小文字
type Category struct { Id string Label string }
idをIdに、labelをLabelにしたらきちんと値が取れるようになった
- 作者: Mat Ryer,鵜飼文敏,牧野聡
- 出版社/メーカー: オライリージャパン
- 発売日: 2016/01/22
- メディア: 大型本
- この商品を含むブログ (2件) を見る
- 作者: 松木雅幸,mattn,藤原俊一郎,中島大一,牧大輔,鈴木健太,稲葉貴洋
- 出版社/メーカー: 技術評論社
- 発売日: 2016/09/09
- メディア: 大型本
- この商品を含むブログ (2件) を見る
python でまずはtwitterにアクセスしてみる
ほぼ公式みればわかること
使用するライブラリ
pip install pyyaml pip install tweepy
config.yaml
config.yamlにConsumer KeyとかAccessTokenとか用意する
動かすコード
# -*- coding: utf-8 -*- import tweepy import yaml def readConfig(): """Read config file""" with open('config.yaml') as reader: y = reader.read() r = yaml.load(y) return r def initializeClient(consumerKey, consumerSecret, accessToken, accessTokenSecret): auth = tweepy.OAuthHandler(consumerKey, consumerSecret) auth.set_access_token(accessToken, accessTokenSecret) return tweepy.API(auth) def main(): config = readConfig() print(config) client = initializeClient(config["consumer_key"], config["consumer_secret"], config["access_token"], config["access_token_secret"]) print(client.me()) if __name__ == '__main__': main()
- 作者: Bill Lubanovic,斎藤康毅,長尾高弘
- 出版社/メーカー: オライリージャパン
- 発売日: 2015/12/01
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (1件) を見る
Pythonによるスクレイピング&機械学習 開発テクニック BeautifulSoup,scikit-learn,TensorFlowを使ってみよう
- 作者: クジラ飛行机
- 出版社/メーカー: ソシム
- 発売日: 2016/12/06
- メディア: 単行本
- この商品を含むブログを見る