Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I parse data from inside a tag with Applescript? I know Applescript has the words 3 thru -2 of myTextVariable syntax - but how would I use it to be sure I am just getting
This is my text from the tags below?

<p>This is my text</p>


<p class="new">This is my text</p>


<h1>This is my text</h1>


<content class="new" id="content">This is my text</content>
share|improve this question
In a hurry, but see: Parsing HTML in AppleScript – slhck Nov 16 '11 at 16:04
up vote 1 down vote accepted

I'd just use regex in the shell or in some shell scripting language:

paragraphs of (do shell script "/bin/echo " & quoted form of "<p class=\"new\">yyy</p><p>uuu</p>" & " | ruby -e 'puts $<.read.scan(/<p.*?>(.+?)<\\/p>/)'")

share|improve this answer
Thanks @Lri I was hoping from an answer from the AppleScript expert :) I had been doing something similar but was just wondering if there was a better way - glad you are in support of using the shell. One thing though, why use /bin/echo instead of echo but not /usr/bin/ruby instead of ruby ? – cwd Nov 17 '11 at 14:06
@cwd Because the default echo in sh eats backslashes: osx - How can I escape shell arguments in AppleScript? - Stack Overflow – user495470 Nov 17 '11 at 18:16

Your Answer


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.