単純なプログラムで、Tempfiles と関係があると思われる問題が発生しています。「open-uri」と「nokogiri」を使用しており、ドキュメントの正規表現検索と nokogiri を使用した xpath 検索を試みています。ただし、ドキュメントに対して2つの別々のリクエストを作成し、2つの別々の一時ファイルを作成しないと、これを行うことはできないようです。これは機能しますが、2 つの要求を行っています。
require 'open-uri'
require 'nokogiri'
source_url = "http://foo.com/"
#grab html document and assign it a variable
doc = open(source_url)
#grab html document, convert to Nokogiri object and assign to variable.
noko_doc = Nokogiri::HTML(open(source_url))
#create array of stuff.
foo = noko_doc.xpath("//some element").collect { |e| e }
#create another array of stuff
bar = []
doc.each do |f|
f.each do |line|
abstract_matches = line.scan(/some regex string/)
unless abstract_matches.empty?
abstract_matches.collect! do |item|
if item.to_s.match(/yet another regex string/)
item
end
end.compact!
unless abstract_matches.empty?
abstract_matches.each { |match| bar << "#{ match } / " }
end
end
end
end
#all for this
puts foo + bar
'doc' 変数を Nokogiri::HTML に渡して、それを繰り返し処理できればと思います。ヘルプ?