Tag: nokogiri
html=<<__EOM__
<html>
<head><title>デモサイト</title></head>
<body>
<h1>見出し</h1>
<div class="container">
<div class="row">行1
</div>
<div class="row">行2
</div>
</div>
</body>
</html>
__EOM__
doc = Nokogiri::HTML.parse(html, nil, 'utf-8')
p doc.title
nodesets = doc.xpath("//div[@class='row']")
p nodesets.class
p nodesets.text
p nodesets.first.class
p nodesets.first.text
$ ruby demo.rb "デモサイト" Nokogiri::XML::NodeSet "行1\n 行2\n " Nokogiri::XML::Element "行1\n "
タグの内部(HTML残す)
テキスト化した内容
gem install nokogiri -v '1.6.5'
checking for xmlParseDoc() in -llibxml2... no ----- libxml2 is missing. Please locate mkmf.log to investigate how it is failing. -----
Undefined symbols for architecture x86_64:
"_iconv", referenced from:
_main in conftest-a4367a.o
"_iconv_open", referenced from:
_main in conftest-a4367a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
export NOKOGIRI_USE_SYSTEM_LIBRARIES=1
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --path vendor/bundle/
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. }}
2018/12/07(金)なぜかこれまで「 NOKOGIRI_USE_SYSTEM_LIBRARIES=1」でビルドできていたRailsプロジェクトがビルドできなくなった。以下のようなエラーメッセージが表示される。
Installing nokogiri 1.8.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/sora/work/myproject/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/Users/sora/.anyenv/envs/rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181207-55660-1avexke.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
pkg-config could not be used to find libxml-2.0
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
pkg-config could not be used to find libxslt
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
pkg-config could not be used to find libexslt
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
NOKOGIRI_USE_SYSTEM_LIBRARIESを指定しないか、以下のようにlibxmlのパスを明示すればインストールできた。
gem install nokogiri -- --use-system-libraries --with-xml2-config=/opt/local/bin/xml2-config --with-xslt-config=/opt/local/bin/xslt-config
NOKOGIRI_USE_SYSTEM_LIBRARIESを指定しなければいいのだが原因がわからない。OSは10.13.6のままかわっていないので、Xcodeのせい?