简体   繁体   English

使用Applescript / Javascript从网页选择中获取图像URL /地址

[英]Get Image URL/Address from webpage selection using Applescript/Javascript

I need a quick way to get the image URL, just like I would get if I right click on an image and select "Copy Image URL". 我需要一种快速的方法来获取图像URL,就像我右键单击图像并选择“复制图像URL”一样。 I'm thinking Applescript, though others have mentioned Javascript. 我在想Applescript,尽管其他人也提到Javascript。

This needs to be compatible with an Automator workflow and needs to work with Google Chrome, Chromium, and Safari, at a minimum. 这必须与Automator工作流程兼容,并且至少需要与Google Chrome,Chromium和Safari兼容。

More specifics: 更多细节:

  1. I already have an Automator workflow that this will be added to. 我已经有一个将添加到其中的Automator工作流程。
  2. The workflow begins with text and images that I have selected on a webpage using the mouse. 工作流程从我使用鼠标在网页上选择的文本和图像开始。
  3. The processing of the text is working fine. 文本处理正常。
  4. I just need a Applescript or Javascript or Shell Script (which I assume are the only outside code that can be added to an Automator workflow) that will grab any and all image URL's within the part of the page selected in step 2. 我只需要一个Applescript或Javascript或Shell脚本(我认为这是可以添加到Automator工作流程中的唯一外部代码),它将在步骤2中选择的页面部分中捕获任何和所有图像URL。
  5. Images are NOT downloaded. 图像未下载。 Only the image URL is needed. 只需要图像URL。

The basic logic is this: 基本逻辑是这样的:

Does selected input contain images?
    If yes, 
    get URL of image(s) 
    pass to the next step
else continue

Any help or ideas appreciated! 任何帮助或想法表示赞赏!

OS X Services would be your best bet. OS X服务将是您最好的选择。 Those work with text selections and are supported in most apps (eg see the Safari>Services submenu). 这些选项可使用文本选择,并且在大多数应用程序中受支持(例如,请参见Safari>“服务”子菜单)。 You can also assign them keyboard shortcuts, which is very handy for repetitive tasks. 您还可以为其分配键盘快捷键,这对于重复性任务非常方便。

Basically, you want to get the selection as web content (ie HTML data, not plain text) then extract the URLs from that. 基本上,您希望将选择内容作为Web内容(即HTML数据,而不是纯文本)获取,然后从中提取URL。 You can create services in Automator, which includes various actions for working with web content, so I recommend starting there. 您可以在Automator中创建服务,其中包括用于处理Web内容的各种操作,因此我建议从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM