can somebody tell me why script editor unexpectedly quits when trying to run this on a big page? it is to download fanfiction.net stories.
and when it is compiled as an application it gives an error
by the way i know it creates a b_1.html and 1.html …
set temp to display dialog "What is the story code?" default answer ""
set code to text returned of temp
set code2 to code
set baseDialog to "http://www.fanfiction.net/s/"
set temp to display dialog "number of pages?" default answer "1"
set i to text returned of temp
set t to 1
try
tell application "Finder" to make new folder at folder "books" of folder "tomcool" of folder "Users" of startup disk with properties {name:code}
end try
set theTitle to get_TITLE(baseDialog, code)
display dialog the theTitle
repeat i times
set urlAddress to baseDialog & code & "/" & t & "/"
set the_HTML to my get_html(urlAddress, true, code, t, i, theTitle)
set t to t + 1
end repeat
renameFolder(code, theTitle)
on renameFolder(code, theTitle)
--display dialog code
--display dialog theTitle
tell application "Finder" to set name of folder code of folder "books" of folder "tomcool" of folder "Users" of startup disk to theTitle
end renameFolder
on get_html(this_URL, save_to_disk, code, t, i, theTitle)
set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
set the_HTML to do shell script "curl " & (quoted form of this_URL) & " -A " & browser_string
set code1a to (offset of "<title>FanFiction.Net : " in the_HTML) + 24
set code1b to (offset of "</title>" in the_HTML) - 1
set code1 to text code1a thru code1b of the_HTML
set code2a to (offset of ");</script>" in the_HTML) + 11
set code2b to (offset of "</span></div>" in the_HTML) - 1
set code2 to text code2a thru code2b of the_HTML
set theCode to "<html><head><title>" & code1 & " page " & t & "</title></head>" & "<body bgcolor=#ffffff>" & code2 & "</body></html>"
if save_to_disk then
do shell script "echo " & (quoted form of the_HTML) & " > ~/books/" & code & "/" & t & ".html"
do shell script "echo " & (quoted form of theCode) & " > ~/books/" & code & "/b_" & t & ".html"
end if
return the_HTML
end get_html
on get_TITLE(baseDialog, code)
set this_URL to baseDialog & code & "/2/" --watch out create new script for one-shot
set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
set the_HTML to do shell script "curl " & (quoted form of this_URL) & " -A " & browser_string
set theTitleStart to (offset of "<title>FanFiction.Net : " in the_HTML) + 24
set theTitleEnd to (offset of "</title>" in the_HTML) - 1
set theTitle to text theTitleStart thru theTitleEnd of the_HTML
return theTitle
end get_TITLE
end