在Ruby中解析网页的最佳方式是什么? [英] What is the best way to parse a web page in Ruby?

查看:99
本文介绍了在Ruby中解析网页的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究rubyforge上的XML和HTML库,以便将数据从网页中提取出来。例如,如果我想解析一个用户页面上的stackoverflow我怎样才能获得数据到一个可用的格式?



说我想解析我自己的用户页面为我目前信誉得分和徽章上市。我试图将从我的用户页面检索到的源代码转换为xml,但由于缺少div,转换失败。我知道我可以做一个字符串比较,并找到我正在寻找的文本,但必须有一个更好的方式来做到这一点。



我想合并这变成了一个简单的脚本,它可以在命令行吐出我的用户数据,并且可能将其扩展到一个GUI应用程序。

角度来说,Hpricot结束!



立即使用 Nokogiri


I have been looking at XML and HTML libraries on rubyforge for a simple way to pull data out of a web page. For example if I want to parse a user page on stackoverflow how can I get the data into a usable format?

Say I want to parse my own user page for my current reputation score and badge listing. I tried to convert the source retrieved from my user page into xml but the conversion failed due to a missing div. I know I could do a string compare and find the text I'm looking for, but there has to be a much better way of doing this.

I want to incorporate this into a simple script that spits out my user data at the command line, and possibly expand it into a GUI application.

解决方案

Hpricot is over !

Use Nokogiri now.

这篇关于在Ruby中解析网页的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆