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>

or

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

or

<h1>This is my text</h1>

or

<content class="new" id="content">This is my text</content>
link|improve this question

1  
In a hurry, but see: Parsing HTML in AppleScript – slhck Nov 16 '11 at 16:04
feedback

1 Answer

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>/)'")

link|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 – Lri Nov 17 '11 at 18:16
feedback

Your Answer

 
or
required, but never shown

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