Soldato
- Joined
- 24 Nov 2002
- Posts
- 16,378
- Location
- 38.744281°N 104.846806°W
I have a Ruby script, but I'm a little stuck.
I'm using page_content.scan to find something on a page but it returns an array. Ideally I just want a string return as there will be ONLY one result.
Secondly, I want an if loop, so that if "s" wasn't found don't have a hissy fit/do nothing and say print "unknown".
Thirdly, I'm using sleep(30) to pause the loop, but I want to rerun the loop on a keypress, possible?
I'm using page_content.scan to find something on a page but it returns an array. Ideally I just want a string return as there will be ONLY one result.
Secondly, I want an if loop, so that if "s" wasn't found don't have a hissy fit/do nothing and say print "unknown".
Thirdly, I'm using sleep(30) to pause the loop, but I want to rerun the loop on a keypress, possible?
Code:
open(url) {
|page| page_content = page.read()
s = page_content.scan(%r{Now:</strong> (.*?)</span>}m).flatten
s.each {|s| puts s}
}
Last edited: