Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

katanna

macrumors 6502
Original poster
May 6, 2004
350
44
Short question: How would I tell AppleScript to look up a specific line of a webpage?

Long question: I want to copy to the clipboard the "Now Playing" song on this site:
http://on-air.897powerfm.com/

I just need the text between "Now Playing" and "What's Played Recently" (without the time, if possible). I like playing around with code (I have several scripts that I have played with), but I don't even know where to start on this. If you could just point me in the right direction, I would appreciate it!

Matthew
 
There is probably a more succinct way to do this, but here is a solution cobbled from another project.

Code:
set theSong to do shell script "curl http://on-air.897powerfm.com/ | grep -E \"[0-9]+:[0-9]+\" | head -1 | sed -E 's/^.*[0-9]+ +[ap]m - (.+[^ ]) +\\([0-9][0-9][0-9][0-9]\\)<br>/\\1/'"


curl - downloads the HTML of the page
grep - pulls out the lines that have numbers, then colon, then numbers (the time stamp)
head - pulls out just the first line of the results
sed - searches that line until it finds a number, followed by a space, followed by am or pm, followed by a space and dash and space and then pulls out everything from that point until it finds some spaces followed by a left parenthesis, followed by 4 digits, followed by a right parenthesis and <br>.

So, it is a little messy, but it works nice.

-numero
 
wow, yay, thanks! You da man! (or woman, as the case may be)

Matthew
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.