SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    just getting started with ruby ... odd problem with Net::HTTP

    require "net/http"
    require 'uri'

    data = Net::HTTP.get(URI.parse('http://news.bbc.co.uk/sport2/hi/football/teams/a/arsenal/live_text/default.stm'))
    puts data


    Very simple script that should print the html from the link to the page right?
    My problem is that the data is being cut off, a quarter of the way through and I can't understand why.
    Any ideas?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    require 'open-uri'
    
    puts open('http://news.bbc.co.uk/sport2/hi/football/teams/a/arsenal/live_text/default.stm')

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may use

    Code:
    begin
    
    rescue
    
    end
    and try to get from the url again, it may hit timeout.

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    FL
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe a different approach:

    Code:
        require 'net/http'
        require 'uri'
    
        url = URI.parse('http://news.bbc.co.uk/sport2/hi/football/teams/a/arsenal/live_text/default.stm')
        result = Net::HTTP.start(url.host, url.port) {|http|
          http.get('/default.stm')
        }
        puts result.body
    Has always worked for me in the past.
    Eric A.
    Founder and CEO, XMG Networks, Inc.
    XMG Services: Web 2.0 Photo Management and Sharing | Web Hosting
    Personal Blog: From Two 2 Twelve

  5. #5
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys ... I was using Free ride and it turns out that it was just cutting off the output even though all the content was actually there.
    I am sorry for wasting your time, and very thankful for all your help regardless.

    - From a guy having way too much fun with Ruby


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •