Last active
July 10, 2023 09:07
-
-
Save corehook/8918448 to your computer and use it in GitHub Desktop.
Самый простой парсер для сайта http://krisha.kz Это если нужно СМС рассылку по риэлторам сделать
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 | |
# 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' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Чувак, а у тебя есть ссылка для запроса чтобы получить список объявлений пользователя?