We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Scraping a web page for data
Page Index Toggle Pages: 1
Scraping a web page for data (Read 517 times)
Scraping a web page for data
Feb 26th, 2009, 1:44am
 
Hi.

I'm trying to do an extremely (or so I thought) simple thing -

I have a url that either returns a 0 or 1. I'm trying to get at that data by modifying the sketch in "Getting Started with Arduino" - example 6.1.

I get (more or less) how to use:

   URL url = new URL(feed);
   URLConnection conn = url.openConnection();
   conn.connect();
   //etc

but I don't know how to parse the data, so that I can simply display "Data = <someval>." Can anyone point me in the right direction?

Eventually I will be writing this data to the arduino itself, but I need to get past this hurdle first.

Thanks in advance for any help.
Re: Scraping a web page for data
Reply #1 - Feb 26th, 2009, 2:13am
 
Take a look at loadStrings() (http://processing.org/reference/loadStrings_.html).  Very simple to use, just pass it the url as a parameter.
Re: Scraping a web page for data
Reply #2 - Feb 26th, 2009, 7:31am
 
You probably want split().
Also remember, if needed, to compare strings by using equals(), not ==.
Re: Scraping a web page for data
Reply #3 - Feb 27th, 2009, 6:05pm
 
Thanks for the replies.

loadStrings() worked like a charm. I tried that before, and it didn't work, that's why I was trying the other method. But the reason loadStrings didn't work before was due to authentication issues on the webserver I was trying. I changed hosts, and it worked as expected.

Thanks again!
Page Index Toggle Pages: 1