0

http://services.tvrage.com/tools/quickinfo.php?show=Chuck

I'm trying to parse that info, for example, get the Airtime,

Airtime@Monday at 08:00 pm

I want to get what's after "Airtime@" till the end of the line, to just come out with "Monday at 08:00 pm". How can I do this?

1
  • 2
    Oh MY GAWD. Please don't overcapitalize. Commented Sep 26, 2010 at 3:32

5 Answers 5

4

Is there any reason you don't use the XML feeds?

require 'open-uri'
require 'nokogiri'

d = Nokogiri.XML(open 'http://services.tvrage.com/feeds/showinfo.php?sid=15614')

name = d.search('//showname').text               # => 'Chuck'
day  = d.search('//airday').text                 # => 'Monday'
time = d.search('//airtime').text                # => '20:00'
net  = d.search('//network[@country="US"]').text # => 'NBC'

puts "#{name} airs #{day}s at #{time} on #{net}."
# Chuck airs Mondays at 20:00 on NBC.
Sign up to request clarification or add additional context in comments.

Comments

2
result = allyourtextdata[/Airtime@(.+)/,1]

Or if you are also going to use some another strings from this report:

hash = Hash[allyourtextdata.scan(/(.+?)@(.+)/)]
p hash["Airtime"] # this will print "Monday at 08:00 pm"

1 Comment

Not exactly what I wanted, but it lead me the way! Thanks man!
1
require 'net/http'
url=URI.parse('http://services.tvrage.com/tools/quickinfo.php?show=Chuck')
response = Net::HTTP.get_response(url)
data=response.body
puts data.scan(/.*Airtime@(.*)\n/)

Comments

0

Why regex? Any problem getting substring?

s = "Airtime@Monday at 08:00 pm"
puts s[8..-1] # => Monday at 08:00 pm

edit
ok, this is for other options

puts s[s.index('@') + 1..-1]

1 Comment

Because there are other options aswell, such as "Show ID", ect.
-1

This is a great site for testing ruby regex expressions: http://rubular.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.