Help with Screen Scraper!

T

Ta St

Hi,

I need some help with a simple screen scraper app. Here's how it works:

1) I open a connection to a url
2) I look for a specific string
3) When I get the string, I do something with it
4) Important: I'm polling a url looking for data changes.

Problem:
Everything works fine, until the website is updated with new content. At
that point, my code throws an "private method `scan' called for
nil:NilClass (NoMethodError)"

I can get the code to work using
begin
....
rescue
retry
end

But, the problem is that it causes the connection to close and re-open.
This causes a further delay in grabbing the data.

Is there a way to handle this? Again, the polling works fine until the
server updates the new page that I'm scanning. At that time, the error
is thrown and I either have to re-open a connection or fail on error. My
Java application seems to be handling this more gracefully, but, Ruby is
faster on the polling. Thanks for any insight.

Regards.


******************
require 'open-uri'
pval = "14"
url="http://www.someurl.com"
stop = false

while stop == false
#Create timestamp
sts="S " << Time.now.strftime("%m/%d/%y %H %M
%S.")<<Time.now.usec.to_s
puts sts
lines=open(url).read.split("\n")
#Get Lines of data and find the SearchValue
tdate=lines.detect {|line| line =~ /SearchValue/}.scan(/\d+/)
#Compare SearchValue to pval
if tdate[1] != pdate

puts tdate[0]
ts="F "<<Time.now.strftime("%m/%d/%y %H %M
%S.")<<Time.now.usec.to_s
else
puts ".."
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need help with this script 4
Help with code 0
my first screen scraper 0
Help with my responsive home page 2
Help please 8
Python battle game help 2
Help with a function 8
Can't solve problems! please Help 0

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top