Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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>
share|improve this question
1  
In a hurry, but see: Parsing HTML in AppleScript –  slhck Nov 16 '11 at 16:04

1 Answer 1

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

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.