class Scraper
Public Class Methods
main()
click to toggle source
# File assignment3-5971.rb, line 23 def self.main lookup_url = 'https://www.set.or.th/set/commonslookup.do' highlight_url = 'https://www.set.or.th/set/companyhighlight.do?symbol=' main_page = Nokogiri::HTML(HTTParty.get(lookup_url)) all_symbol = main_page.css('tr td a').map(&:text) all_symbol.each do |symbol| link = highlight_url + symbol scraper(link) end end
scraper(url)
click to toggle source
# File assignment3-5971.rb, line 9 def self.scraper(url) unparsed_page = HTTParty.get(url) parse_content = Nokogiri::HTML(unparsed_page.body) company = parse_content.css('h3').text index = 4 asset = parse_content.css('tr')[2].css('td') loop do asset = parse_content.css('tr')[2].css('td')[index] index -= 1 break if !asset.nil? || index == 1 end puts "#{company}: #{asset.text}" end