Can you provide examples of parsing HTML?

后端 未结 29 2719
走了就别回头了
走了就别回头了 2020-11-22 13:49

How do you parse HTML with a variety of languages and parsing libraries?


When answering:

Individual comments will be linked to in answers to questions

29条回答
  •  爱一瞬间的悲伤
    2020-11-22 14:34

    language: Ruby
    library: Hpricot

    #!/usr/bin/ruby
    
    require 'hpricot'
    
    html = ''
    ['foo', 'bar', 'baz'].each {|link| html += "#{link}" }
    html += ''
    
    doc = Hpricot(html)
    doc.search('//a').each {|elm| puts elm.attributes['href'] }
    

提交回复
热议问题