2014年6月20日 星期五

Go HTML Parser

用Go寫爬蟲目前有兩個third party library還滿好用的。

  1. gokogiri: https://github.com/moovweb/gokogiri
  2. goquery: https://github.com/PuerkitoBio/goquery

gokogiri使用cgo封裝了libxml2,所以需要先安裝libxml2,環境架設比較麻煩,弄好之後可以用XPath的方式取element。而goquery基於Go的net/html以及cascadia,讓我們可以使用類似Jquery Selector的方式選取element。

Selector使用方式可以參考http://api.jquery.com/category/selectors/

搭配goquery的Readme變換一下selector應該就可以寫出一些基本的爬蟲了。

2014年6月6日 星期五

Mac OSX 安裝Go開發環境(Vim)

安裝Go

https://code.google.com/p/go/wiki/Downloads?tm=2下載go1.2.2.darwin-amd64-osx10.8.pkg照步驟安裝。

設定GOPATH

vim ~/.bash_profile

加入

export GOPATH=/Users/vampirewalk/develop/go
export PATH=$GOPATH/bin:$PATH

使用Vundle管理Vim plugin

參照 https://github.com/gmarik/Vundle.vim

安裝vim-go

在.vimrc裏面加入

Plugin 'fatih/vim-go'

然後在vim裏面:PluginInstall

設定colorscheme

curl -o ~/.vim/colors https://raw.githubusercontent.com/fatih/molokai/master/colors/molokai.vim
vim ~/.vimrc

在vimrc中,在” Put your non-Plugin stuff after this line之後加入

syntax on        
colorscheme molokai
set t_Co=256

autocmd BufNewFile,BufReadPost *.go set filetype=go

安裝YouCompleteMe

https://github.com/Valloric/YouCompleteMe

調整MacVim的字型

vim ~/.gvimrc

寫入

set guifont=Monaco:h16

完成囉,開始開發吧