Skip to content

Instantly share code, notes, and snippets.

@corehook
Last active July 10, 2023 09:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save corehook/8918448 to your computer and use it in GitHub Desktop.
Save corehook/8918448 to your computer and use it in GitHub Desktop.
Самый простой парсер для сайта http://krisha.kz Это если нужно СМС рассылку по риэлторам сделать
#!/usr/bin/env ruby
# simple krisha.kz parser for bro
# 3 minute code
# Result
# server@corehook:~/projects/crawlers/krisha.kz$ ruby krisha.rb http://krisha.kz/arenda/kvartiry/almaty/
# +7 (701) 4405729
# +7 (771) 4882860
# +7 (701) 4405729
# +7 (771) 4882860
# +7 (707) 3960194
# +7 (701) 8511580
# +7 (707) 3960194
# +7 (701) 8511580
# +7 (707) 3960194
# +7 (707) 3960194
# +7 (778) 1769206
# ^Ckrisha.rb:33:in `write': Interrupt
require 'curb'
require 'nokogiri'
raise 'enter url mozofaka' if ARGV.count != 1
def get_number(id)
http = Curl.get("http://krisha.kz/ajax/show-advert-phones?id=#{id}") do|http|
http.headers['X-Requested-With'] = 'XMLHttpRequest'
end
return http.body_str if http.response_code == 200
return nil
end
numbers = []
next_url=ARGV[0]
loop {
response = Curl.get(next_url)
next_url = 'none'
break if response.response_code != 200
doc = Nokogiri::HTML(response.body_str)
doc.xpath('//a[contains(@href, "a/show")]').each do |s|
number = get_number(s.values[0].split('/')[-1])
next if number.nil?
number.split(',').each do |n|
print n,"\n"
end
end
doc.xpath('//a').each do |s|
next_url = "http://krisha.kz/#{s.values[0]}" if s.text.include? "\u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0430\u044F"
end
break if next_url.eql? 'none'
}
@thewindalmaty
Copy link

thewindalmaty commented Apr 24, 2016

Здравствуйте!

Я вообще не программист, просто ищу квартиру. На Вашу страницу зашел через поиск в Гугле. Я так понял ваш скрипт дает возможность сформировать рассылку по риэлторам?

@XcenaX
Copy link

XcenaX commented Sep 13, 2019

Чувак, а у тебя есть ссылка для запроса чтобы получить список объявлений пользователя?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment