2019-01-24 20:30:05 Ruby

Ruby

Copy Copied! Full
#weblio英単語レベル取得をnokogiriなしで require "uri";require "open-uri" puts "*plz type something*" begin loop do if (word=gets.chomp.to_s)==nil puts "*Well, let me see...*" if word =~ /^[a-zA-Z]+$/ open(URI.encode("https://ejje.weblio.jp/content/#{word}")){|mean| data=mean.read.scan(/learning-level-table-wrap(.*)語彙力テストを受ける/).flatten[0] .scan(/>(.*?)</).flatten.delete_if{|a|a==""} data.size.times{|i|i%3==2? data[i]=data[i]+"/":i%3==1? data[i]=":":nil} p "Level:#{data[2]}英検#{data[5].scan(/\w+/)[0]}級↑/#{data[8]}TOEIC:#{data[11].scan(/\d+/)[0]}↑/#{data[-1]}" exit;puts data[-1].include?(":") ? data[-1].gsub('"',"") : "*nope: いや,いいえ*" } else puts "*日本語: Japanese*" end if word == "exit" ||word == "end" ||word == "finish";sleep(3);exit;end else puts "*駄目: tabu,taboo*" end end rescue Interrupt puts '*interrupt: (…を)さえぎる,中断する,腰を折る*' end
RECOMMEND