Problem with getting rid of <br /> tag

I’m writing a script to grab the lyrics for either the current song in iTunes or a certain song, and it all works fine and the lyrics are saved to a text file but the
tags are still there… Whats wrong with it?

Entire Code:


display dialog "Please specify the type of lyric search:" buttons {"Song being played on iTunes", "Specify song"} default button "Song being played on iTunes"
if the button returned of the result is "Song being played on iTunes" then
	tell application "iTunes"
		set theSong to the name of the current track as text
		set theArtist to the artist of the current track as text
		display dialog theArtist & return & theSong
	end tell
else
	display dialog "What is the song called?" default answer ""
	set theSong to text returned of result
	
	display dialog "Who is the artist?" default answer ""
	set theArtist to text returned of result
end if

set theSong to edittext(theSong)
set theArtist to edittext(theArtist)


set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theSong to text items of theSong
set theArtist to text items of theArtist

set AppleScript's text item delimiters to {"_"}
set theSong to theSong as Unicode text
set theArtist to theArtist as Unicode text
set AppleScript's text item delimiters to {""}

get "http://www.lyricwiki.org/" & theArtist & ":" & theSong
do shell script "/usr/bin/curl --user-agent '' " & quoted form of result
set theLyrics to result

set AppleScript's text item delimiters to {"<div id=\"lyric\">"}
set theLyrics to (last text item of theLyrics) as Unicode text

set AppleScript's text item delimiters to {"</div>"}
set theLyrics to first text item of theLyrics

set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics

set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID
on edittext(someText)
	-- Remove anything that is not alphanumeric or a space
	return do shell script "echo " & quoted form of someText & " | /usr/bin/ruby -ne 'print $_.delete(\"^a-z\", \"^A-Z\", \"^0-9\", \"^ \")'"
end edittext
set user_text to theLyrics
set file_name to (choose file name with prompt "Please type a file name" default name theSong & ".txt")
if file_name as string does not end with ".txt" then set file_name to ((file_name as string) & ".txt")
my make_report(file_name, user_text)

set dMes to return & return & "Would you like to open the  file now?"
set opts to (display dialog "Done!" & dMes buttons {"Yes", "No Thanks"} default button 1 with icon 1 giving up after 30)
if button returned of opts is "Yes" or gave up of opts is true then
	tell application "TextEdit"
		activate
		try
			open (file_name as alias)
		on error errMs
			display dialog errMs buttons {"Cancel"}
		end try
	end tell
end if -- button is "Done"

to make_report(file_name, user_text)
	try
		do shell script "rm " & quoted form of POSIX path of file_name
	end try
	
	try
		set fileRefr to (a reference to (open for access file_name with write permission))
		write user_text to fileRefr
		close access fileRefr
	on error errx number errNum from badObj
		try
			close access fileRefr
		end try
		log errNum
		if (errNum is equal to -48) then
			do shell script "rm " & quoted form of POSIX path of file_name
			my make_report()
		else
			display dialog "There has been an error creating the file:" & return & return & (badObj as string) & errx & return & "error number: " & errNum buttons {"Cancel"}
		end if
	end try
end make_report
on error_and_cancel(ms)
	if gave up of (display dialog ms with icon 2 buttons {"Cancel"} default button 1 giving up after 15) then error number -128
end error_and_cancel



I’m guessing the problem is somewhere here:

set AppleScript's text item delimiters to {"<br />"}
set theLyrics to text items of theLyrics

set AppleScript's text item delimiters to {""}
set theLyrics to text 2 thru -1 of (theLyrics as Unicode text)
set AppleScript's text item delimiters to ASTID

Hi Hendo,

look carefully at your delimiter “
” and remove the space character :wink:

but when i look at the source code from the host website thats what their br tags look like

EDIT…but it worked anyway haha, Thanks StefanK

maybe firefox is just weird…or maybe im getting old…but im only 17 so that shouldn’t be the problem…lol