0

この HTML タグ文字列を見つけるための AppleScript ルーチンまたはサブルーチンを探しています。

<td width="487">

この HTML コードで:

                <h1><span id="profile-name-94461" >Jan Schlatter</span></h1>



            </span>

            <table width="100%" border="0" cellspacing="0" cellpadding="0" id="profile-table">
                                    <tr>
                    <th width="163" scope="col">Introduction</th>
                    <td width="487">Education :
<br />Management and support on responsibilities in finances and accounting.</td>
                </tr>
                                                        <tr>
                    <th>Role</th>
                    <td>
                    <p>Portfolio Management</p><p>Senior Management</p>                     </td>
                </tr>
                <tr>  
                    <th>Organisation Type</th>
                    <td>
                    <p>Family Office</p>                        </td>
                </tr>
                <tr>
                    <th>Email</th>
                    <td><a href="mailto:jan.schlatter@bohnetschlatter.ch" title="jan.schlatter@bohnetschlatter.ch" >jan.schlatter@bohnetschlatter.ch</a></td>
                </tr>
                <tr>
                    <th>Website</th>
                    <td><a href="http://bohnetschlatter.ch" target="_new" title="http://bohnetschlatter.ch" >http://bohnetschlatter.ch</a></td>
                </tr>
                <tr>
                    <th>Phone</th>
                    <td>+41 41 727 61 61</td>
                </tr>
                <tr>
                    <th>Fax</th>
                    <td>+41 41 727 61 62</td> 
                </tr>
                <tr>
                    <th>Mailing Address</th>
                    <td>Gartenstrasse 2<br>Postfach 42</td>
                </tr>
                <tr>
                    <th>City</th>
                    <td>Zurich</td>
                </tr>
                <tr>
                    <th>State</th>
                    <td></td>
                </tr>
                <tr>
                    <th>Country</th>
                    <td>Switzerland</td>
                </tr>
                <tr>
                    <th class="lastrow" >Zip/ Postal Code</th>
                    <td class="lastrow" >6301</td>
                </tr>
        </table>

HTML タグは、処理したいすべての HTML ファイルに常にあるとは限らないため、if、then、else ステートメントで使用されるブール値を返し、値が「true」を返す場合にアクションを完了するようにしたいと考えています。 "。

私が始めたapplescriptは

set intoTag to "<td width=" & quote & "487" & quote & ">"
   on stripLastWordBeforeLogoEndTag(theText)
  set text item delimiters to introTag
  set a to text items of theText
  set b to item 1 of a
  set text item delimiters to space
  set item 1 of a to (text items 1 thru -2 of b) as text
  set text item delimiters to "</Logo>"
  set fixedText to a as text
  set text item delimiters to ""
return fixedText

if infoTag = fixedText then set bool to true
else set bool to false
end if

if true then (do action[[set extractText_INTRODUCTION to extractBetween(extractText, "<td width=" & quote & "487" & quote & ">", "</td>")]])
else (do not do action)
end if

シェルスクリプトの編集方法についてほとんど知識がないため、シェルスクリプトを使用したくありません。私の観点では、テキスト区切り文字が最良の解決策ですが、どんな回答でも大歓迎です。ありがとう

4

2 に答える 2

3

最も簡単なのは使用することですis in

set introTag to "<td width=\"487\">"
set existTag to introTag is in theText
if existTag then
    -- true
else
    -- false
end if
于 2012-04-21T02:26:59.993 に答える
1

シェル スクリプトを使用したくない場合は、Standard Additions のoffsetコマンドを使用できます。これは、あるテキスト内の別のテキストを検索します。テキストが見つからない場合、結果は 0 になり、if ステートメントで使用できます。次に例を示します。

set theText to "...<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\"profile-table\">
                                    <tr>
                    <th width=\"163\" scope=\"col\">Introduction</th>
                    <td width=\"487\">Education :..."

set here to offset of "<td width=\"487\">" in theText
if here is not 0 then
    log "text found at " & here -- do your stuff
end if
于 2012-04-21T01:02:43.177 に答える