これが私のコードです..
require "open-uri"
base_url = "http://en.wikipedia.org/wiki"
(1..5).each do |x|
# sets up the url
full_url = base_url + "/" + x.to_s
# reads the url
read_page = open(full_url).read
# saves the contents to a file and closes it
local_file = "my_copy_of-" + x.to_s + ".html"
file = open(local_file,"w")
file.write(read_page)
file.close
# open a file to store all entrys in
combined_numbers = open("numbers.html", "w")
entrys = open(local_file, "r")
combined_numbers.write(entrys.read)
entrys.close
combined_numbers.close
end
ご覧のように。基本的には、ウィキペディアの記事 1 から 5 までのコンテンツをスクレイピングし、それらを numbers.html という 1 つのファイルに結合しようとします。
それは最初のビットを正しく行います。しかし、2番目になると。ループの5番目の記事の内容に書き込むだけのようです。
どこが間違っているのかわかりません。何か助けはありますか?