ruby – 如何从字符串中删除HTML编码字符?
发布时间:2020-12-16 21:21:12 所属栏目:百科 来源:网络整理
导读:我有一个包含一些 HTML编码字符的字符串,我想删除它们: "lt;divgt;Hi All,lt;/divgt;lt;div class="paragraph_break"gt;lt; /gt;lt;/divgt;lt;divgt;Starting today we are initiating PoLS.lt;/divgt;lt;div class="paragraph_break"gt;lt;br /gt;lt;/
我有一个包含一些
HTML编码字符的字符串,我想删除它们:
"<div>Hi All,</div><div class="paragraph_break">< /></div><div>Starting today we are initiating PoLS.</div><div class="paragraph_break"><br /></div><div>Please use the following communication protocols:<br /></div><div>1. Task Breakup and allocation - Gravity<br /></div><div>2. All mail communications - BC messages<br /></div><div>3. Reports on PoC / Spikes: Writeboard<br /></div><div>4. Non story related tasks: BC To-Do<br /></div><div>5. All UI and HTML will communicated to you through BC.<br /></div><div>6. For File sharing,we'll be using Dropbox.<br /></div><div>7. Use Skype for lighter and generic desicussions. However,in case you need any approvals,data for later reference,etc,then please use BC. PoLS conversation has been created on skype.</div><div class="paragraph_break"><br /></div><div>You'll have been given necessary accesses to all these portals. Please start using them judiciously.</div><div class="paragraph_break"><br /></div><div>All the best!</div><div class="paragraph_break"><br /></div><div>Thanks,<br /></div><div>Saurav<br /></div>" 解决方法
你想做的事情是多方面的.也许看看你为什么要这样做会有所帮助.通常当我想删除编码的HTML时,我想恢复HTML的内容. Ruby有一些模块可以让它变得简单.
require 'cgi' require 'nokogiri' html = "<div>Hi All,<br /></div><div>Saurav<br /></div>" puts CGI.unescapeHTML(html) 哪个输出: <div>Hi All,</div><div class="paragraph_break">< /></div><div>Starting today we are initiating PoLS.</div><div class="paragraph_break"><br /></div><div>Please use the following communication protocols:<br /></div><div>1. Task Breakup and allocation - Gravity<br /></div><div>2. All mail communications - BC messages<br /></div><div>3. Reports on PoC / Spikes: Writeboard<br /></div><div>4. Non story related tasks: BC To-Do<br /></div><div>5. All UI and HTML will communicated to you through BC.<br /></div><div>6. For File sharing,we'll be using Dropbox.<br /></div><div>7. Use Skype for lighter and generic desicussions. However,then please use BC. PoLS conversation has been created on skype.</div><div class="paragraph_break"><br /></div><div>You'll have been given necessary accesses to all these portals. Please start using them judiciously.</div><div class="paragraph_break"><br /></div><div>All the best!</div><div class="paragraph_break"><br /></div><div>Thanks,<br /></div><div>Saurav<br /></div> 如果我想更进一步并删除标签,检索所有文本: puts Nokogiri::HTML(CGI.unescapeHTML(html)).content 将输出: Hi All,Starting today we are initiating PoLS.Please use the following communication protocols:1. Task Breakup and allocation - Gravity2. All mail communications - BC messages3. Reports on PoC / Spikes: Writeboard4. Non story related tasks: BC To-Do5. All UI and HTML will communicated to you through BC.6. For File sharing,we'll be using Dropbox.7. Use Skype for lighter and generic desicussions. However,then please use BC. PoLS conversation has been created on skype.You'll have been given necessary accesses to all these portals. Please start using them judiciously.All the best!Thanks,Saurav 当我看到那种字符串时,这是我通常想要的地方. Ruby的CGI使编码和解码HTML变得容易. Nokogiri宝石可以轻松删除标签. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ruby-on-rails – 如何通过rake任务传递-f specd
- c# – 如何在Windows Phone 8.1中使用正确的旋转
- SQLite剖析(10):异步IO模式、共享缓存模式和解锁
- 整合Flex+struts+BlazeDS+tomcat+mysql
- quick-cocos2dx的addNodeEventListener事件
- 解决flexbuilder中的一个困扰:字符串的隐含字符
- 学习React Native必看的几个开源项目(第二波)
- 交叉编译 – autotools:C编译器无法创建可执行文
- SQLite之SQLiteStatement
- cocos2d-x 游戏暂停界面,监听home键,返回键,M
热点阅读