Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Small HTML-skimming Applescript

Small HTML-skimming Applescript
Thread Tools
Junior Member
Join Date: Feb 2001
Location: Portland/OR/USA
Status: Offline
Reply With Quote
Jul 8, 2004, 04:06 AM
 
Would this be something I could make easily in Applescript? (I can only make the most beginner "hello world" programs) - I work for a newspaper and we have a movie ratings scorecard, with empty, half and whole moon shapes to denote how a given film was reviewed. Since we get all of this info from metacritic.com, and have a 0-40, 41-79, and 80-100 scale, would it be that hard to make an Applescript to take the numbers from metacritic.com and spit out certain letters or symbols?
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jul 8, 2004, 06:35 AM
 
Hi,

Here's a fragile script that should work if the page design doesn't change at all...

All it does is get the score in the front window of safari - but it could be extended very easily... I'm just not sure how you put your paper together.

[php]
on run
-- Get the source of the Page.
tell application "Safari"
set the reviewSource to the source of the front document
-- Get the meta-tag - this is very fragile and could easily break with a small change to the site
set metaTagSource to the fifth paragraph of reviewSource as text
end tell


-- Search for the metaScore part of the tag
set savedTextItemDelimiters to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {"METASCORE="}
set brokenUpTagParts to text items of metaTagSource
set scoreBitWithTrailingData to second item of brokenUpTagParts

-- refine
set AppleScript's text item delimiters to {"."}
set metaScore to first item of text items of scoreBitWithTrailingData

--reset the text item delimiters:
set AppleScript's text item delimiters to savedTextItemDelimiters
on error m number n from f to t partial result p
--also reset text item delimiters in case of an error:
set AppleScript's text item delimiters to savedTextItemDelimiters
--and resignal the error:
-- error number n from f to t partial result p
display dialog "Could not find the score. - are you sure the front window is a metascore review?" buttons {"OK"} default button 1
return
end try

display dialog "MetaScore: " & metaScore buttons {"OK"} default button 1

end run


[/php]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:40 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2