四月
4
2008

爬虫Crawler让你下载bt数据不用为看广告烦恼

首先你要有ruby

可以上网下载一个instant ruby
然后在命令行模式下输入:gem install mechanize 来安装爬虫库

最后我的爬虫程序:

require ‘rubygems’
require ‘mechanize’

contents = []
title=[]
link=[]
agent = WWW::Mechanize.new
agent.user_agent_alias = ‘Mac Safari’
page = agent.get(“http://share.greedland.net/index.php“)
page.body.scan( /(<tr>.*?<\/tr>)/m ) {  |item|
link = item[0].scan( /<a href=\”#\” onclick=\”window.open\(\’.*?<a href=(.*?)class=black.*?<\/a>/ )
link = link[0][0] if ( link[0].length > 0 )
title = item[0].scan( /onmouseout=\”hideTip\(\)\;\”>(.*?)<\/a>/ )
title = title[0][0] if ( title[0].length > 0 )
puts “<a href=”+link+” >”+title+”</a><br />”
}

#  puts page.body

这个是用来爬贪婪大陆的bt列表的.你可以很容易的修改为其他bt站点.
做到web上就可以很好的实现web2.0和mashup啦

相关文章

我要评论

标签