ruby抓取URL内容并解析页面所有URL_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > ruby抓取URL内容并解析页面所有URL

ruby抓取URL内容并解析页面所有URL

 2010/12/30 8:05:46  zhwj184  http://zhwj184.javaeye.com  我要评论(0)
  • 摘要:#-*-coding:ISO-8859-1-*-require'open-uri'require'uri'html=open('http://www.265.com/').read(2000000)END_CHARS=%{.,'?!:;}putsURI.extract(html,['http']).collect{|u|END_CHARS.index(u[-1])?u.chop:u}运行结果:http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional
  • 标签:Ruby URL 内容
# -*- coding: ISO-8859-1 -*-

require 'open-uri' 
require 'uri'

html = open('http://www.265.com/').read(2000000) 

END_CHARS = %{.,'?!:;}
puts URI.extract(html, ['http']).collect { |u| END_CHARS.index(u[-1]) ? u.chop : u }

?

?

运行结果:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
http://www.w3.org/1999/xhtml
http://www.google.com.hk/search?hl=zh-CN&q=%E7%94%B5%E5%BD%B1&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f&oq=&client=aff-avalanche
http://google.com.hk/webhp?hl=zh-cn&tab=Aw
http://www.google.cn/imghp?hl=zh-cn&tab=Ai
http://video.google.cn/?hl=zh-cn&tab=Av
http://ditu.google.cn/maps?hl=zh-cn&tab=Al
http://news.google.cn/nwshp?hl=zh-cn&tab=An
http://www.google.cn/music?hl=zh-cn&tab=AU
http://www.google.cn/prdhp?hl=zh-cn&tab=Af
http://www.google.com.hk/intl/zh-CN/options/
http://www.google.cn/music?client=aff-avalanche&channel=textlink
http://www.265.com/images/googlemusic.gif
http://www.google.cn/search?hl=zh-CN&client=aff-avalanche&forid=1&channel=logo&q=
http://www.google.com.hk/search?hl=zh-CN&q=
http://www.365rili.com/
http://www.boc.cn/cn/common/whpj.html
http://www.google.com.hk/finance?client=aff-a&hl=zh-CN
http://jipiao.kuxun.cn/?fromid=Kgbw-S1134381-T1137511
http://huoche.kuxun.cn/?fromid=Kgbw-S1134381-T1076521
http://www.lottery.gov.cn/
http://www.zhcw.com/
http://www.google.com.hk/search?hl=zh-CN&q=%E7%94%B5%E5%BD%B1&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f&oq=&client=aff-avalanche
http://www.google.com.hk/dictionary
http://www.google.com.hk/intl/zh-CN/help/features.html
http://www.google.com.hk/intl/zh-CN/mobile/maps/
http://www.chashouji.com/
http://product.cheshi.com/price.html
http://fund.eastmoney.com/fund.html
http://www.google.com.hk/search?hl=zh-CN&q=
http://www.google.com.hk/search?hl=zh-CN&q=
http://download.tech.qq.com/soft/17/21/index.shtml
http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&q=%E8%B0%B7%E6%AD%8C%E9%87%91%E5%B1%B1%E8%AF%8D%E9%9C%B8&aq=f&aqi=&aql=&oq=&gs_rfai=
http://www.uusee.tv/
http://earth.google.com/intl/zh-CN/
http://www.360.cn
http://www.kuaikuai.cn/h/down/kk_game/?channel=57_1
http://www.flashget.com/cn/download.htm
http://www.ppstream.com/download.html
http://pstatic.xunlei.com/about/product/down_xl5.htm
http://www.google.com/ime/pinyin/
http://toolbar.google.com/T4/intl/zh-CN/
http://www.kuwo.cn/
http://www.rising.com.cn/
http://www.maxthon.cn/
http://www.stockstar.com/cfg
http://www.QVOD.com
http://feixin.10086.cn/download/
http://www.gw.com.cn/download/level1/index.htm
http://www.google.com.hk/search?q=%E6%9A%B4%E9%A3%8E%E5%BD%B1%E9%9F%B33.6+%E6%99%BA%E8%83%BD%E9%AB%98%E6%B8%85%E7%89%88&hl=zh-CN&source=billboard_site&cd=12200098&cad=5&ie=utf8
http://www.google.com/chrome?hl=zh-cn
http://www.mosh.cn/beijing
http://www.wooha.com/?WT.mc_id=new265
http://www.qunar.com/
http://www.abang.com/
http://www.yihaodian.com/product/index.do?tracker_type=9&tracker_u=1949358
http://www.izhufu.com/
http://www.docin.com
http://bai.sohu.com
http://www.daodao.com/?m=12347
http://www.gong1chuang1.com
http://www.mpdaogou.com/
http://www.aibaimm.cn/
http://www.bankrate.com.cn/
http://www.5925car.com/
http://www.miui.com/
http://www.trends.com.cn/
http://www.m18.com/
http://www.0-6.com/
http://www.chilema.cn/default.aspx
http://www.51mike.com/
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#609
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#352
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1134
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1371
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#963
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1372
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1373
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1437
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1374
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#355
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1438
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#957
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1417
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1376
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#958
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1378
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1135
http://www.265.com/Youxi_Wangyou/Remen_Youxizhuanti_All.html#1377
http://www.265.com/Youxi_Wangyou/index.html#196
http://www.265.com/Youxi_Wangyou/index.html#195
http://www.google.com.hk/webhp?client=aff-avalanche
http://www.baidu.com/
http://www.qq.com/
http://www.163.com/
http://cn.msn.com/
http://www.tom.com/
http://www.china.com/
http://www.sina.com.cn/
http://www.sohu.com/
http://cn.yahoo.com/
http://www.51job.com/
http://www.renren.com/
http://www.mop.com/
http://www.chinamobile.com/
http://www.ifeng.com/
http://www.eastmoney.com/
http://www.people.com.cn/
http://www.xinhuanet.com/
http://www.ctrip.com/
http://www.360.cn/
http://www.soufun.com/
http://www.cctv.com/
http://www.zaobao.com/
http://www.xunlei.com/
http://58.com/
http://www.icbc.com.cn/
http://www.kaixin001.com/
http://www.4399.com/
http://www.jrj.com.cn/
http://www.hexun.com/
http://www.gov.cn/
http://china.alibaba.com/?cosite=265dh&location=alihomepage_dh
http://www.taobao.com/
http://www.zol.com.cn
http://www.zhcw.com/
http://www.autohome.com.cn/
http://www.youku.com
http://www.tudou.com/
http://www.jiayuan.com/
http://www.dangdang.com/
http://www.tianya.cn/
http://www.51.com/?fromsite=265_1
http://news.google.com.hk/news/search?pz=1&cf=all&ned=cn&hl=zh-CN&q=%E6%B2%BB%E5%A0%B5&source=265.com',
http://news.google.com.hk/news/more?pz=1&cf=all&ned=cn&cf=all&ncl=dVZ221HiynUgGMMdPA7YVmSj8eZRM&source=265.com',
http://news.google.com.hk/news/more?pz=1&cf=all&ned=cn&cf=all&ncl=dlDTKEYmgUS-GKMcA1iendnuqffNM&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&num=10&topic=e&bcid=1651226638&bc_lang=zh-CN&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&topic=fe&bcid=1651764651&bc_lang=zh-CN&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&num=10&topic=fe&bcid=1651435361&bc_lang=zh-CN&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&num=10&topic=fe&bcid=1650340552&bc_lang=zh-CN&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&num=10&topic=fe&bcid=1651458816&bc_lang=zh-CN&source=265.com',
http://blogsearch.google.com.hk/blogsearch/story?hl=zh-cn&topic=l&bcid=1651766213&bc_lang=zh-CN&source=265.com',
http://news.google.com.hk/news/more?pz=1&cf=all&ned=cn&cf=all&ncl=dZkub0JsW0461gMDeDdtdN4qp-pMM&source=265.com',
http://news.google.com.hk/news/search?pz=1&cf=all&ned=cn&hl=zh-CN&q=%E5%85%AC%E5%8A%A1%E5%91%98%E5%B7%A5%E8%B5%84&source=265.com',
http://news.google.com.hk/news/more?pz=1&cf=all&ned=cn&cf=all&ncl=dQhOS-yAc2hsqbMejJ2S82D9XA0CM&source=265.com',
http://news.google.com.hk/news/search?pz=1&cf=all&ned=cn&hl=zh-CN&q=%E5%BC%A0%E9%9B%A8%E7%BB%AE&source=265.com',
http://www.17173.com
http://games.sina.com.cn/
http://www.duowan.com/
http://game.zol.com.cn
http://tl.sohu.com/
http://aion.sdo.com/project/index/index.htm
http://t.mop.com
http://www.onlinedown.net/
http://www.skycn.com/
http://www.crsky.com
http://xiazai.zol.com.cn
http://tech.sina.com.cn/down/
http://www.mydown.com/
http://www.qidian.com/
http://www.readnovel.com/
http://www.xxsy.net/
http://www.hongxiu.com/
http://www.jjwxc.net/
http://book.sina.com.cn/
http://www.xs8.cn/
http://military.china.com/zh_cn/
http://mil.news.sina.com.cn/
http://www.tiexue.net/
http://mil.huanqiu.com/
http://www.xinhuanet.com/mil/
http://junshi.xilu.com/
http://sports.sina.com.cn/
http://sports.sohu.com/
http://sports.163.com/
http://sports.tom.com/
http://china.nba.com/
http://www.hoopchina.com/
http://www.zhibo8.com/
http://www.google.cn/music/homepage?client=aff-avalanche
http://www.1ting.com/
http://www.haoting.com/
http://www.qq163.com/
http://www.aiting.com
http://www.520music.com/
http://youku.com
http://tudou.com
http://www.ku6.com/
http://www.6.cn
http://www.joy.cn/
http://video.sina.com.cn/
http://tv.sohu.com/
http://www.google.com.hk/finance?client=aff-a&hl=zh-CN
http://www.jrj.com.cn/
http://eastmoney.com/
http://www.stockstar.com/
http://www.cnfol.com/
http://hexun.com/
http://finance.qq.com/
http://people.com.cn/
http://xinhuanet.com/
http://www.chinanews.com.cn/
http://news.sina.com.cn/
http://news.google.com.hk/news?ned=cn&client=aff-avalanche
http://www.china.com.cn
http://news.ifeng.com
http://www.tianya.cn
http://www.qihoo.com
http://www.xici.net
http://www.daqi.com
http://www.dianping.com
http://dzh.mop.com
http://laiba.tianya.cn
http://blog.sina.com.cn/
http://www.bokee.com/
http://blog.163.com/
http://blog.sohu.com/
http://hi.baidu.com
http://qzone.qq.com/
http://www.jiayuan.com/
http://www.marry5.com/
http://www.baihe.com/
http://www.zhenai.com/
http://www.ipart.cn/
http://www.wealink.com/
http://www.myspace.cn/
http://www.lol99.com/
http://www.4399.com/
http://www.7k7k.com/
http://www.51mole.com/
http://www.yx007.com/
http://www.3839.com/
http://www.xiaoyouxi.com/
http://www.91wan.com/
http://mail.163.com/
http://mail.cn.yahoo.com
http://mail.sohu.com
http://www.hotmail.com/
http://www.gmail.com/
http://www.126.com/
http://mail.sina.com.cn/
http://www.39.net/
http://www.xywy.com/
http://www.haodf.com/
http://health.sohu.com/
http://www.fx120.net/
http://www.fh21.com.cn/
http://www.jxdyf.com/
http://www.pclady.com.cn
http://eladies.sina.com.cn/
http://women.sohu.com/
http://lady.163.com/
http://www.lady8844.com/
http://www.zdface.com/
http://www.yoka.com/
http://www.icbc.com.cn/index.jsp
http://www.boc.cn/
http://www.ccb.com/portal/cn/home/index.html
http://www.abchina.com/
http://www.bankcomm.com/
http://www.cmbchina.com/
http://www.cib.com.cn/
http://finance.sina.com.cn/fund/
http://fund.jrj.com.cn/
http://www.1234567.com.cn/
http://www.chinaamc.com/
http://www.jsfund.cn/
http://www.gffunds.com.cn/
http://autohome.com.cn/
http://www.pcauto.com.cn/
http://www.xcar.com.cn/
http:///www.chinacars.com
http://www.cheshi.com/
http://www.bitauto.com/
http://www.che168.com/
http://www.51job.com/
http://zhaopin.com/
http://chinahr.com/
http://www.yingjiesheng.com/
http://www.cjol.com/
http://www.528.com.cn/
http://taobao.com/
http://union.360buy.com/union_default.aspx?union_Id=163
http://www.amazon.cn/
http://www.dangdang.com/
http://www.google.com.hk/products?client=aff-avalanche
http://www.newegg.com.cn?cm_mmc=265com-_-265com-_-265com-_-1110
http://58.com
http://www.55bbs.com/
http://www.anjuke.com/
http://www.koubei.com/
http://www.ci123.com/
http://www.yaolan.com/
http://www.aibangtuan.com/
http://house.sina.com.cn/
http://www.google.com.hk/webhp?client=aff-avalanche
http://www.baidu.com/
http://one.cn.yahoo.com/
http://ditu.google.com/maps?client=aff-avalanche
http://www.google.com.hk/products?client=aff-avalanche
http://www.google.cn/music?client=aff-avalanche
http://video.google.com.hk/?client=aff-avalanche
http://images.google.com.hk/images?client=aff-avalanche
http://news.google.com.hk/nwshp?client=aff-avalanche
http://www.265.com/');return(false)
http://www.265.com
http://www.google.cn/intl/zh-CN/about.html
http://www.265.com
http://www.miibeian.gov.cn/

?

发表评论
用户名: 匿名