Getting webpage content with Ruby — I'm having troubles

后端 未结 3 1256
一生所求
一生所求 2020-12-14 21:53

I want to get the content off this* page. Everything I\'ve looked up gives the solution of parsing CSS elements; but, that page has none.

Here\'s the only code that

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 22:35

    The appropriate way to fetch the content of a website is through the NET::HTTP module in Ruby:

    require 'uri'
    require 'net/http'
    url = "http://hiscore.runescape.com/index_lite.ws?player=zezima"
    r = Net::HTTP.get_response(URI.parse(url).host, URI.parse(url).path)
    

    File.open() does not support URIs.

    Best wishes,
    Fabian

提交回复
热议问题