Skip to content

Instantly share code, notes, and snippets.

@nazargulov
Created September 30, 2015 06:25
Show Gist options
  • Select an option

  • Save nazargulov/40af033c0229d2371628 to your computer and use it in GitHub Desktop.

Select an option

Save nazargulov/40af033c0229d2371628 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'Nokogiri'
require 'json'
url = 'https://vk.com/away.php?to=https%3A%2F%2Fwww.avito.ru%2Fsankt-peterburg%2Fkvartiry%2Fsdam%2Fna_dlitelnyy_srok%2F1-komnatnye%3Fuser%3D1%26view%3Dlist%26metro%3D168-186-204'
html = open(url)
doc = Nokogiri::HTML(html)
showings = []
doc.css('.item item_list js-catalog-item-enum clearfix c-b-0 cat_24').each do |item|
item_id = item['id'].split('_').last.to_i
item.css('.title').each do |titleall|
title_el = titleall.at_css('h3 a')
title = title_el.text.strip
showings.push(id: item_id, title: title)
end
end
puts JSON.pretty_generate(showings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment