【发布时间】:2014-02-02 18:03:11
【问题描述】:
目标:如果订单中包含“发件人:”一词,我需要退款的一长串订单,并且每次购买都有一个订单号,我一直在尝试解析或循环,但不确定单词是否正确 搜索 HTML doc for单词“From:”的实例,如果找到,则获取其他数字并打印到文本文件。
到目前为止,我已经学会了如何使用文本项目分隔符,但是当我尝试让它循环或重复时,我只是一遍又一遍地得到相同的订单号。这是在尝试实现如果订单详细信息包含单词“from”然后获取订单号的部分之前。
set astid to AppleScript's text item delimiters
set x to 2
set startHere to "p class=\"webOrderNumber\">"
set stopHere to "</p>"
set entireText to (do shell script "curl file:///Users/Michael/Desktop/StorePurchases.webarchive")
set AppleScript's text item delimiters to startHere
set blurb1 to text item x of entireText
repeat with i from 2 to (count of blurb1)
set thisItem to item i of blurb1
set AppleScript's text item delimiters to stopHere
set blurb2 to text item 1 of blurb1
set AppleScript's text item delimiters to astid
set writeFile to ((path to desktop as text) & "test_output") --
set writeData to blurb2
set success to appendDataToFile(writeData, writeFile)
end repeat
on appendDataToFile(myData, aFile)
set OA to (open for access aFile with write permission)
try
write (myData & (ASCII character 10)) as text to OA starting at eof
close access OA
return true
on error
try
close access OA
end try
return false
end try
end appendDataToFile
这里是 HTML 的摘录:
</td>
<td class="OrderNumber">
<p class="webNumber">BHWL123456</p>
</p>
<td class="OrderNumber">
<p class="details">
Full Version: Get all Activities & Remove ads! [From: Pony Resort: MakeverMagic] </p>
</td>
当有数百个订单需要很长时间才能实际搜索 FROM 一词并写入订单号时,将使用此选项。
【问题讨论】:
-
您想要达到的目标在 AppleScript 中非常困难。如果真的没有必要使用 AppleScript 并且您有一些其他语言的经验,您应该考虑使用其他东西。
标签: html parsing applescript delimiter