Những gì bạn muốn làm là nhiều cách doable. Có lẽ nhìn vào lý do tại sao bạn có thể muốn làm điều đó sẽ giúp. Thông thường khi tôi muốn xóa HTML được mã hóa, tôi muốn khôi phục nội dung của HTML. Ruby có một số mô-đun giúp dễ dàng.
require 'cgi'
require 'nokogiri'
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>"
puts CGI.unescapeHTML(html)
mà kết quả đầu ra:
<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>
Nếu tôi muốn mang nó một bước xa hơn và loại bỏ các thẻ, lấy tất cả các văn bản:
puts Nokogiri::HTML(CGI.unescapeHTML(html)).content
Will đầu ra:
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, in case you need any approvals, data for later reference, etc, 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
Đó là nơi tôi thường muốn để có được khi tôi thấy loại chuỗi đó.
Ruby CGI giúp mã hóa và giải mã HTML dễ dàng. Đá quý Nokogiri giúp bạn dễ dàng xóa thẻ.
Bạn đã thử gì? Và chuyện gì đã xảy ra khi bạn thử? –
Bạn có thể thêm kết quả mong muốn không? Là loại khó hiểu những gì bạn thực sự cần. Không chắc chắn nếu bạn muốn xóa chúng hoặc chỉ giải mã chúng. Có thể bạn cần phải loại bỏ một số và giải mã những người khác? – robertodecurnex