LoginSignup
3
3

More than 5 years have passed since last update.

食べログのWebページから店舗のURLと点数を抽出するrubyプログラム

Last updated at Posted at 2017-07-24

rubyと食べログ初心者です!

タグ付けの部分はスペース区切りなのか... ruby,はNG

「食べログからWebページから店舗のURLと点数を抽出するrubyプログラム」
未完成だけどいちおう動く
コメントアウトしたところは勉強用とデバグ用に残してます

tabe_test.rb
require "uri"
require "pp"

href = []
score = []
shop_name = []
url = ""





File.open("./tabe_test.txt").each do |line|
    if line =~ %r|list-rst__rst-name|
#       score << line.scan(%r|\d.\d{2}|).to_s
        url = line.scan(%r|/">.+</a|).to_s
        url.gsub!(%r|/">|, "")
        url.gsub!(%r|</a|, "")
#       url.chomp!
        shop_name << url
    end
end



File.open("./tabe_test.txt").each do |line|
    if line =~ %r|"list-rst__rst-name-target cpy-rst-name"|
        href << URI.extract(line, ["https"]).to_s
    end
end

File.open("./tabe_test.txt").each do |line|
    if line =~ %r|list-rst__rating-val|
        score << line.scan(%r|\d.\d{2}|).to_s
    end
end




shop_name.each do |shop_n| puts shop_n end

shops = [score, href].transpose
#shops = [shop_name, href].transpose

#shops = [href, shop_name].transpose

#pp shop_name
pp shops

shops.each do |shop|
    if shop[0].to_f > 3.5
        puts shop[1]
    end
end

#File.open("tabe_test_result.txt", "w+") do |f| 
 # f.puts(str)
#end



#keys = ["募集", "残り", "キャンセル待ち"]
#values = [20, 0, 2]
# pairs = [keys, values].transpose
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3