require 'nokogiri' doc = Nokogiri.HTML <<-eot <p>Here you can find <a href="ssNODELINK/SurvivalStatistics">Survival stats </a> <a href="ssNODELINK/SmokingStatistics">Smoking stats </a> <a href="ssNODELINK/RisksAndCauses"> and Risks </a> <a target="_blank" href="http://www.something.ac.uk/"> Something </a> of recent research</p> eot nodesets = doc.css('p > a') nodesets.each do |nd| nd.unlink if nd['href'].include? 'ssNODELINK' end puts doc # >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> # >> <html><body><p>Here you can find # >> # >> # >> # >> <a target="_blank" href="http://www.something.ac.uk/"> Something </a> # >> of recent research</p></body></html>
# >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> # >> <html><body><p>Here you can find # >> <a target="_blank" href="http://www.something.ac.uk/"> Something </a> # >> of recent research</p></body></html>
Any help on this regard ?