Skip to content

Instantly share code, notes, and snippets.

@oki
Created January 23, 2009 15:54
Show Gist options
  • Select an option

  • Save oki/51055 to your computer and use it in GitHub Desktop.

Select an option

Save oki/51055 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'pp'
# sudo gem install hpricot
# http://www.katalogiseo.info/str-2-1,60.html
# http://www.katalogiseo.info/str-2-1,120.html
# http://www.katalogiseo.info/str-2-1,180.html
def img_true?(*html)
html.map { |img|
img.attributes['src'] =~ /N\.png/ ? false : true
}
end
dir_count = 0
60.step(5820,60) { |n| puts n
url = "http://www.katalogiseo.info/str-2-1,#{n}.html"
puts "#{url}..."
html = open(url).read
doc = Hpricot html
doc.search("table.bodyline > tr > td > table > tr").each { |e|
id = e.at("td").inner_text.to_s.gsub(/\[(\d+)\]/,'\1')
next if id !~ /^\d+$/
dir_count += 1
type = e.at("td").siblings_at(2).inner_text
dir = e.at("td > div > div > a.linki")
dir_name = dir.inner_text
dir_url = dir.attributes['href']
back_link = img_true?(e.at("td").siblings_at(3).at('img'))
free, mod = img_true?(*e.at("td").siblings_at(4).search("img"))
puts ">>> #{dir_url} - #{dir_name}"
puts " >>> #{type}"
puts " >>> back_link?/free/mod : #{back_link}/#{free}/#{mod}"
}
}
puts "count: #{dir_count}"
# 60
# http://www.katalogiseo.info/str-2-1,60.html...
# >>> http://www.dir.comoj.com - Katalog dir.comoj.com
# >>> qlWeb by Jachu
# >>> back_link?/free/mod : false/true/false
# >>> http://randki.amor.com.pl - Katalog AMOR
# >>> ABIX
# >>> back_link?/free/mod : true/true/true
# >>> http://maszynykat.pl - Katalog Maszyny Do Metalu
# >>> qlWeb
# >>> back_link?/free/mod : false/true/true
# >>> http://blog.tb3.pl - P.Page To Be Free
# >>> WordPress
# >>> back_link?/free/mod : false/true/true
# >>> http://www.pres.impresa.pl - P.Page Impresa
# >>> MocneLinki
# >>> back_link?/free/mod : false/true/false
# etc....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment