I have been given ASP and HTML files which contain HTML and some JavaScript code. I have to write a Rails application which will retrieve links from those pages and show them in Rails views.
I am stuck. Will Nokogiri help?
答案 0 :(得分:1)
是的,它会。
# open and read your HTML file as Nokogiri::HTML document
doc = File.open("your_file.html") { |f| Nokogiri::HTML(f) }
# collect all links that have not empty href attribute
links = doc.css('a').map { |link| link['href'] }.reject { |link| link.blank? }