AppleScript Text delimiters "Can’t get text items"
<p>I'm trying to get AppleScript to find some Data from a Web site and copy them as text.</p>

<p>However sometime I have the error : error "Can’t get text items 2 thru -1 of \"correct@data.com\"." number -1728 from text items 2 thru -1 of "correct@data.com"</p>

<p>Any idea? </p>

<pre><code>to getInputByClass(theClass, num) -- defines a function with two inputs, theClass and num
    tell application "Safari" --tells AS that we are going to use Safari
        set input to do JavaScript "
document.getElementsByClassName('" &amp; theClass &amp; "')[" &amp; num &amp; "].innerHTML;" in document 1 -- uses JavaScript to set the variable input to the information we want
    end tell
    return input --tells the function to return the value of the variable input
end getInputByClass


-- start here
getInputByClass("spacebefore", 0)

set theText to getInputByClass("spacebefore", 0)

-- clear text
set DATA1ID to extractText(theText, "\"&gt;", "&lt;/td&gt;")
to extractText(searchText, startText2, endText)
    set tid to AppleScript's text item delimiters
    set startText1 to "x"
    set searchText to ("x" &amp; searchText)
    set AppleScript's text item delimiters to startText1
    set endItems to text item -1 of searchText
    set AppleScript's text item delimiters to endText
    set beginningToEnd to text item 1 of endItems
    set AppleScript's text item delimiters to startText2
    set finalText to (text items 2 thru -1 of beginningToEnd)
    set AppleScript's text item delimiters to tid
    return finalText
end extractText

-- DATA1ID Found

to getInputByClass2(theClass, num) -- defines a function with two inputs, theClass and num
    tell application "Safari" --tells AS that we are going to use Safari
        set input to do JavaScript "
document.getElementsByClassName('" &amp; theClass &amp; "')[" &amp; num &amp; "].innerHTML;" in document 1 -- uses JavaScript to set the variable input to the information we want
    end tell
    return input --tells the function to return the value of the variable input
end getInputByClass2


-- start here
getInputByClass2("inspectDSInInspector", 0)

set theText to getInputByClass2("inspectDSInInspector", 0)

-- clear text
set DATA2DSID to extractText2(theText, "&lt;/a&gt;", "&lt;/td&gt;")
to extractText2(searchText, startText2, endText)
    set tid to AppleScript's text item delimiters
    set startText1 to "x"
    set searchText to ("x" &amp; searchText)
    set AppleScript's text item delimiters to startText1
    set endItems to text item -1 of searchText
    set AppleScript's text item delimiters to endText
    set beginningToEnd to text item 1 of endItems
    set AppleScript's text item delimiters to startText2
    set finalText to (text items 2 thru -1 of beginningToEnd)
    set AppleScript's text item delimiters to tid
    return finalText
end extractText2


set finalResult to "DATA2DSID: " &amp; DATA2DSID &amp; "
DATA1ID: " &amp; DATA1ID

set the clipboard to finalResult


tell application "System Events" to keystroke "v" using command down
</code></pre>

<p>UPDATE :</p>

<pre><code>&lt;td class="inspectDATAInInspector"&gt;&lt;a href="/WebObjects/DATA.DATA/DT/DDDDTTTAAAADDTA/0.1.0"&gt;&lt;/a&gt;48784745&lt;/td&gt;
</code></pre>

<p>"href="/WebObjects/DATA.DATA/DT/DDDDTTTAAAADDTA/0.1.0">48784745" is not a fix data, what won't change is   and what I need is the random number at the end, in this case 48784745</p>

<p>The script I made here is working here, but just time to time I have the message mentioned. I think it's could be because I have to convers the data to Plain text until HTML or something like that.</p>