Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Finding text with JavaScript for Widget

Author Message
iindigo



Joined: 11 Feb 2005
Posts: 2

Posted: Fri Feb 11, 2005 - 7:25 pm    Post subject: Finding text with JavaScript for Widget Reply with quote

I'm writing a widget that tells me if my local school is cancelled due to weather. I need it to go to http://wvde.state.wv.us/closings/county/all/ and check to see if the words "greenbrier" and "All-Closed", "Some-closed", or "Delay" exist in a certain order, then change it's appearance accordingly. I have an idea of how to do this with PHP, but widgets require JavaScript. How would I do this in JavaScript?



Thanks!
View user's profile Send private message Send e-mail Widgets
blurry
Quality Control


Joined: 03 Feb 2005
Posts: 33
Location: UK

Posted: Fri Feb 11, 2005 - 9:10 pm    Post subject: Reply with quote

Here's what I'd try:

1) Use XMLHttpRequest to retrieve the webpage.
2) Get the response text, and use a regular expression to match what you're after
3) If you get a match, school is cancelled or delayed! Go back to bed!

The regular expression would be quite straight-forward, but a chore to write because the markup on the page is nasty (font tags, non-breaking spaces and so forth).

You might be able to treat the HTML as XML (depending on how XMLHttpRequest gets HTML - I've only ever fetched XML with it), and so iterate over certain nodes to see if you can get the data you need.

I'd nag the people who do the site and get them to either use CSS so you can scrape the data much more easily, or publish an RSS feed of the information.

George.
_________________
If your only tool is a hammer, everything looks like a nail
View user's profile Send private message Send e-mail Widgets
iindigo



Joined: 11 Feb 2005
Posts: 2

Posted: Fri Feb 11, 2005 - 10:32 pm    Post subject: Reply with quote

Thanks for the help Smile

Could maybe post some example code that shows how to scrape off a website using your method? I've googled all over the place and folund nothing. Sorry to be an annoyance - I'm new to Javascript, as I'm a PHP/CSS man Razz

Thanks again!
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group