How do I pretty-print HTML with Nokogiri?

前端 未结 7 961
梦如初夏
梦如初夏 2020-12-01 10:58

I wrote a web crawler in Ruby and I\'m using Nokogiri::HTML to parse the page. I need to print the page out and while messing around in IRB I noticed a pr

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 11:24

    I know I am extremely late to answer this question, but still, I'll leave the answer. I tried all the above steps and it does work to an extent.

    Nokogiri does format the HTML but does not care about the closing or the opening tag, hence pretty format is out of the picture.

    I found a gem called htmlbeautifier that works like a charm. I hope other people who are still searching for the answer will find this valuable.

提交回复
热议问题