I am trying to achieve a basic substitution but I am finding it difficult to determine the behaviour here.
I want to replace the tags with the URL contained inside it.
This is my code:
require 'nokogiri' message = "Hi Testin wFAASF, Thank you for booking with us. Your work has been booked on Sep 16, 2020 1:00PM at 2026 South Clark Street / unit c / Chicago, Illinois 60616 Sincerely, Varun Security <a href=\"https://www.google.com\">Test This PR</a>" puts message.gsub(Nokogiri::HTML.parse(message).at('a'), Nokogiri::HTML.parse(message).at('a')['href']) What I think the output would be:
"Hi Testin wFAASF, Thank you for booking with us. Your work has been booked on Sep 16, 2020 1:00PM at 2026 South Clark Street / unit c / Chicago, Illinois 60616 Sincerely, Varun Security https://www.google.com What the actual output is:
"Hi Testin wFAASF, Thank you for booking with us. Your work has been booked on Sep 16, 2020 1:00PM at 2026 South Clark Street / unit c / Chicago, Illinois 60616 Sincerely, Varun Security <a href=\"https://www.google.com\">https://www.google.com</a>" Could someone explain why this is happening and how I could do this better?
https://stackoverflow.com/questions/66701148/issue-with-gsub-method-in-my-ruby-code-when-trying-to-replace-html-a-tags-with March 19, 2021 at 08:52AM
没有评论:
发表评论