Getting webpage content with Ruby — I'm having troubles

后端 未结 3 1258
一生所求
一生所求 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:36

    You really want to use open() provided by the Kernel class which can read from URIs you just need to require the OpenURI library first:

    require 'open-uri'
    

    Used like so:

    require 'open-uri'
    file = open('http://hiscore.runescape.com/index_lite.ws?player=zezima')
    contents = file.read
    puts contents
    

    This related SO thread covers the same question:

    Open an IO stream from a local file or url

提交回复
热议问题