简单的红宝石解析 [英] simple parsing in ruby

查看:99
本文介绍了简单的红宝石解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

在Ruby中解析HTML文档的方法?

如果在变量结果中有:

If in the variable results I have:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><link             rel="stylesheet" type="text/css" href="http://2.ai/styles/hello.css" media="screen"/><title>Welcome to Dotgeek.org * 1.ai</title></head><body>..... etc

如何在不使用任何gem的情况下解析我现在具有的HTML页面的标题?

How can I parse, if possible without using any gem, the title of that HTML page that I now have in the results variable?

推荐答案

html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><link rel="stylesheet" type="text/css" href="http://2.ai/styles/hello.css" media="screen"/><title>Welcome to Dotgeek.org * 1.ai</title></head>'
html.match(/<title>(.*)<\/title>/)[1] #=> "Welcome to Dotgeek.org * 1.ai"

这篇关于简单的红宝石解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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