Skip to content

Instantly share code, notes, and snippets.

@sergii
Forked from Mikke/Gemfile
Created March 4, 2014 12:03
Show Gist options
  • Save sergii/9345278 to your computer and use it in GitHub Desktop.
Save sergii/9345278 to your computer and use it in GitHub Desktop.
bundle install
rails g controller parser yandex
gem 'nokogiri'
class ParserController < ApplicationController
# для получения контента через http
require 'open-uri'
# подключаем Nokogiri
require 'nokogiri'
def yandex
end
end
class ParserController < ApplicationController
# для получения контента через http
require 'open-uri'
# подключаем Nokogiri
require 'nokogiri'
def yandex
source = 'http://catalog.yandex.ru/'
# получаем содержимое веб-страницы в объект
page = Nokogiri::HTML(open(source.to_s + page))
end
end
class ParserController < ApplicationController
# для получения контента через http
require 'open-uri'
# подключаем Nokogiri
require 'nokogiri'
def yandex
source = 'http://catalog.yandex.ru/'
# получаем содержимое веб-страницы в объект
page = Nokogiri::HTML(open(source.to_s + page))
# производим поиск по элементам с помощью css-выборки
page.css('a.b-rubric__list__item__link').each do |link|
data = Hash.new
data['text'] = link.content
data['href'] = link['href']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment