在Ruby中解析网页的最佳方式是什么? [英] What is the best way to parse a web page in 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.
Use Nokogiri now.
这篇关于在Ruby中解析网页的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!