Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on a Automator workflow, I am passing list of URLs to the "Run Applescript" and I need to fetch the contents of on each page, concatenate and pass it to a BBedit (or any other text editor).

on run {input, parameters}

    tell application "BBEdit"
        activate

        set astid to AppleScript's text item delimiters

        set startHere to "<tbody>"
        set stopHere to "</tbody>"

        repeat with anItem in input

            set blurb0 to (do shell script "curl " & anItem)
            set AppleScript's text item delimiters to startHere
            set blurb1 to text item 2 of blurb0
            set AppleScript's text item delimiters to stopHere
            set blurb2 to text item 1 of blurb1

            set AppleScript's text item delimiters to astid

            return blurb2
            beep

        end repeat      

    end tell

end run

The current code only properly gets only the contents from first URL. Can anybody fix this?

share|improve this question

1 Answer

This subroutine may be what you need (if you're using Safari)...

on getSource(this_URL)
    tell application "Safari"
        activate
        set the URL of the current tab of document 1 to this_URL
        set the |source| to the source of the front document
    end tell
    tell application "TextEdit"
        activate
        set the text of the front document to the source
    end tell
    quit application "Safari"
end getSource

Call it using:

repeat with anItem in input
    getSource(input)
end repeat

I hope this helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.