Created
October 4, 2017 02:27
-
-
Save tesths/1f40ff19d403c9e32fd3a50e61985b4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'nokogiri' | |
require 'open-uri' | |
require 'byebug' | |
class Food | |
def initialize(d, d1, d2, s) | |
@date = d | |
@dish1 = d1 | |
@dish2= d2 | |
@soap = s | |
end | |
def getDate() | |
@date | |
end | |
def getDish1() | |
@dish1 | |
end | |
def getDish2() | |
@dish2 | |
end | |
def getSoap() | |
@soap | |
end | |
end | |
# Fetch and parse HTML document | |
food_site = Nokogiri::HTML(open('http://www.2sx.net/forum.php?mod=forumdisplay&fid=201')) | |
food_detail_site = 'http://www.2sx.net/' + food_site.xpath("//a[@class='s xst']")[1]['href'] | |
food_detail = Nokogiri::HTML(open(food_detail_site)) | |
data_array = [] | |
food_detail.xpath("//div[@class='pl bm']//div[1]//div[@class='pcb']//td[@class='t_f']").each do |data| | |
data_array.push(data.content) | |
end | |
data = data_array[0] | |
food_array = [] | |
data_array[0].split("\n").each do |food| | |
if food.length > 5 | |
food_array.push(food) | |
end | |
end | |
my_subs = { '月' => '.', '日' => '' } | |
food_det = food_array[0].split(/[[:space:]][[:space:]]/) | |
if food_det[0].include?('月') || food_det[0].include?('日') | |
food_det[0] = '2017.' + food_det[0].split('').map{|i| my_subs[i] || i}.join | |
end | |
food_array.each do |food| | |
data = food.split(/[[:space:]][[:space:]]/) | |
if data[0].include?('月') || data[0].include?('日') | |
data[0] = '2017.' + data[0].split('').map{|i| my_subs[i] || i}.join | |
end | |
food = Food.new(data[0], data[1], data[2], data[3]) | |
puts food.getDate | |
puts food.getDish1 | |
puts food.getDish2 | |
puts food.getSoap | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment