pc を u24e に変えてから、Ruby で mechanize を使ったクロールをしていなかったので、
インストールからすることになった。
バージョンは 2.5.1。
OS は Windows7。
Ruby のプログラミングは
D:¥usr¥local¥ruby
の下に workspace があって、そこにソースを置いている。
Ruby と gem は既にインストールされているので、
mechanize のインストールは gem で行う。
D:¥usr¥local¥ruby>gem install mechanize
Fetching: net-http-digest_auth-1.2.1.gem (100%)
Fetching: net-http-persistent-2.7.gem (100%)
Fetching: mime-types-1.19.gem (100%)
Fetching: nokogiri-1.5.5-x86-mingw32.gem (100%)
Fetching: ntlm-http-0.1.1.gem (100%)
Fetching: webrobots-0.0.13.gem (100%)
Fetching: unf_ext-0.0.5-x86-mingw32.gem (100%)
Fetching: unf-0.0.5.gem (100%)
Fetching: domain_name-0.5.4.gem (100%)
Fetching: mechanize-2.5.1.gem (100%)
Successfully installed net-http-digest_auth-1.2.1
Successfully installed net-http-persistent-2.7
Successfully installed mime-types-1.19
Successfully installed nokogiri-1.5.5-x86-mingw32
Successfully installed ntlm-http-0.1.1
Successfully installed webrobots-0.0.13
Successfully installed unf_ext-0.0.5-x86-mingw32
Successfully installed unf-0.0.5
Successfully installed domain_name-0.5.4
Successfully installed mechanize-2.5.1
10 gems installed
Installing ri documentation for net-http-digest_auth-1.2.1...
Installing ri documentation for net-http-persistent-2.7...
Installing ri documentation for mime-types-1.19...
unable to convert U+2013 from UTF-8 to Windows-31J for lib/mime/types.rb, skipping
unable to convert "¥xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for Licence.rdoc, skipping
Installing ri documentation for nokogiri-1.5.5-x86-mingw32...
unable to convert "¥xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.ja.rdoc, skipping
unable to convert "¥xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
unable to convert "¥xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.ja.rdoc, skipping
unable to convert "¥xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for ext/nokogiri/xml_node_set.c, skipping
Installing ri documentation for ntlm-http-0.1.1...
Installing ri documentation for webrobots-0.0.13...
Installing ri documentation for unf_ext-0.0.5-x86-mingw32...
Installing ri documentation for unf-0.0.5...
Installing ri documentation for domain_name-0.5.4...
Installing ri documentation for mechanize-2.5.1...
unable to convert "¥xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
Installing RDoc documentation for net-http-digest_auth-1.2.1...
Installing RDoc documentation for net-http-persistent-2.7...
Installing RDoc documentation for mime-types-1.19...
unable to convert U+2013 from UTF-8 to Windows-31J for lib/mime/types.rb, skipping
unable to convert "¥xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for Licence.rdoc, skipping
Installing RDoc documentation for nokogiri-1.5.5-x86-mingw32...
unable to convert "¥xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.ja.rdoc, skipping
unable to convert "¥xE8" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
unable to convert "¥xE9" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for README.ja.rdoc, skipping
unable to convert "¥xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for ext/nokogiri/xml_node_set.c, skipping
Installing RDoc documentation for ntlm-http-0.1.1...
Installing RDoc documentation for webrobots-0.0.13...
Installing RDoc documentation for unf_ext-0.0.5-x86-mingw32...
Installing RDoc documentation for unf-0.0.5...
Installing RDoc documentation for domain_name-0.5.4...
Installing RDoc documentation for mechanize-2.5.1...
unable to convert "¥xE3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to Windows-31J for CHANGELOG.rdoc, skipping
何か文字コードの指定をしなければいけないのだろうか、
たくさん警告が出ているようだが気にしない。
さて、今まで使っていたスクリプトでは hpricot を使っていたので、
これをインストールしようとしたら、エラーになった。
D:¥usr¥local¥ruby>gem install hpricot
Fetching: hpricot-0.8.6.gem (100%)
ERROR: Error installing hpricot:
The 'hpricot' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
指定されているサイトを見ると、DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe というインストーラーがあるので、これをダウンロードして実行する。
実行時に、展開先を聞いてくる。
ruby の実行環境は D:¥ruby に入っているので、
D:¥ruby¥devkit というディレクトリを作成し、そこを指定した。
展開が終わると、devkit ディレクトリの下に、いくつかのディレクトリとファイルが生成されている。
D:¥ruby¥devkit>ruby dk.rb init
[INFO] found RubyInstaller v1.9.3 at D:/ruby/Ruby193
Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.
D:¥ruby¥devkit>ruby dk.rb review
Based upon the settings in the 'config.yml' file generated
from running 'ruby dk.rb init' and any of your customizations,
DevKit functionality will be injected into the following Rubies
when you run 'ruby dk.rb install'.
D:/ruby/Ruby193
D:¥ruby¥devkit>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'D:/ruby/Ruby193'
[INFO] Installing 'D:/ruby/Ruby193/lib/ruby/site_ruby/devkit.rb'
なお、devkit に関する情報は、
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
を参照した。
これで hpricot をインストールする準備が整った。
D:¥ruby¥devkit>gem install hpricot
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed hpricot-0.8.6
1 gem installed
Installing ri documentation for hpricot-0.8.6...
Installing RDoc documentation for hpricot-0.8.6...
むぅ、¥ruby¥devkit で実行してしまったが、大丈夫なのか?
この後、とりあえずスクリプトを実行したら、
user_agent_alias の指定のところでエラーが出てしまったが、
実行はできているようだ。