我有大约3,600个html文件,里面有大量的图像标签。我希望能够捕获这些文件中使用的所有 src 属性值并将它们汇总到一个文本文件中,然后我可以删除重复项并查看有多少唯一图像文件名有整体。
我使用BBEdit,我可以轻松使用正则表达式和多文件搜索来查找所有图像引用(18,673),但我不想用任何东西替换它们 - 相反,我想从BBEdit中捕获它们搜索结果'注释'并将它们推送到另一个文件中。
这可能是AppleScripted吗?或者是否有其他适合同一目的的手段?
答案 0 :(得分:1)
你在那里完成了一项艰巨的任务,因为你需要解决很多这方面的问题。为了给你一个开始,这里有一些关于读取一个html文件并将所有src图像放在applescript列表中的建议。你必须做更多的事情,但这是一个开始。
首先,您可以将html文件作为常规文本读入AppleScript。这样的东西会得到一个html文件的文本......
set theFile to choose file
set htmlText to read theFile
将文本转换为AppleScript后,您可以使用文本项分隔符来获取src图像。这是一个例子。无论html代码有多复杂,它都应该有用......
set htmlText to "<img src=\"smiley.gif\" alt=\"Smiley face\" height=\"42\" width=\"42\" />
<img src=\"smiley.gif\" alt=\"Smiley face\" height=\"42\" width=\"42\" />
<img src=\"smiley.gif\" alt=\"Smiley face\" height=\"42\" width=\"42\" />"
set text item delimiters to "src=\""
set a to text items of htmlText
if (count of a) is less than 2 then return
set imageList to {}
set text item delimiters to "\""
repeat with i from 2 to count of a
set thisImage to first text item of (item i of a)
set end of imageList to thisImage
end repeat
set text item delimiters to ""
return imageList
我希望有所帮助!