2008-11-18 20 views
4

主题:以编程方式在OS X 10.4.x + Tiger/Leopard中操作Web浏览器。 目标:从Safari收集/读取/提取网址到文本文件(Ruby on Rails代码)文件。 注意:使用FF的解决方案也非常值得赞赏。我使用Safari(v。3.x,OS X 10.4.x)更喜欢在Safari中运行的解决方案。Webkit/Safari/Firefox/API:我可以通过编程读取/提取多个选项卡的URL吗?

有时,我使用网络浏览器来查找/显示多个网站页面,我希望稍后再次访问以及2)我希望将其组成一个文本文件的URL以供将来参考和/或b)以编程方式操作。

例如:在今天的纽约时报,我觉得我要张贴到我的del.icio.us ACCT 7页纽约时报的文章。并通过电子邮件以其“打印友好”格式进行分享,这些格式在当天的在线版标题之后很长。我在浏览器窗口的水龙头中打开每一个,然后Presto!他们的URL会被自动地绑定到一个文件中,一个(自定义的)Ruby on Rails应用程序将打印版本的URL发送到电子邮件地址和我的Del.icio.us文件。

我认为有一种方法可以使用Applescript或Automator从操作系统执行URL提取步骤。我认为可能有一种方法可以用Javascript来完成。

我的问题:如何读取网页浏览器的标签位置字段和整理这些字符串到一个文本文件(无论是我的操作系统中或通过线路的Web应用程序。)?

非常感谢。

+0

如果/当你知道这一点 - 你肯定需要分享它回到世界..我喜欢这样的事情! – warren 2008-11-18 16:12:04

回答

1

如果你想做到这一点是Firefox,你将不得不学习和使用XUL。这些标签对javascript来说是不可见的(安全/隐私问题),除了Firefox以外,没有这类信息的API。

Getting Started with XUL development是如何在XUL开始编程的好资源。

IBM为您的第一个XUL代码提供了一个decent tutorial

这里是一个tab handler in XUL给你如何处理标签的想法。

一个short tutorial that demonstrates混合XUL,JavaScript和其他技术来更新网站。

最后,这里有一个很好的lifehacker tutorial on firefox extensions/add-ons,它向你展示了上面的一个简单示例,然后如何将它打包为一个.xpi文件,以便其他人可以轻松地将它添加到firefox中并对其进行管理。

我没有任何洞察到Safari浏览器,但它是基于WebKit和应该有对定制它类似于你会如何使用XUL在Firefox的一些资源。

祝你好运!

-Adam

2

对于Safari来说,对于Applescript来说,这将是非常微不足道的。我建议从Bookmark all tabs开始,获取您需要的基本制表符逻辑,也可以将它合并到John Gruber的旧脚本Save and restore Safari URLs中,以将URL保存为文本文件列表。

也可能有更好的Applescript解决方案;这些只是我通过Google找到的第一个,而且都非常过时。

如需进一步帮助和有关AppleScript的资源,我建议MacScripter forums

祝你好运!

0

Firefox中的最简单的办法是“书签所有打开的标签”(在书签菜单)。给这个“书签文件夹”一个特定的名字。然后你可以进入你的个人资料(http://support.mozilla.com/en-US/kb/Profiles)并打开包含你想要的所有信息然后一些的“bookmarks.html”文件。

如果您想使用的用户界面,检查出禁忌和“Sitzungs-管理器”(可能是会话管理器)。两者都是用于Firefox 3.0+

禁忌允许您保存选项卡“后阅读”(有点像书签菜单,而只是一个单一的点击,将节省的页面的截图,太)。

会话管理器插件可以让您保存当前打开的标签页和窗口后恢复它们。

0

你可以修改这个bit-0-code让你开始。我用它来为一个标签创建我自己的个人书签插件。您可以在xul窗口中弹出一个url列表,然后选择您想要发布/ arrogate到一个地方的列表。

function getGetDocData(){ 
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] 
       .getService(Components.interfaces.nsIWindowMediator); 
var mainWindow = wm.getMostRecentWindow("navigator:browser"); 
var tab = mainWindow.getBrowser().selectedTab; 
titleDG = tab.label; 
for(var i = 0; i < window.opener.length; i++){ 
    var doc = window.opener[i].document; 
    if(doc.title == tab.label){ 
     hrefToDG = doc.location.href; 
    } 
} 

}

0

这里是AppleScript的一个脚本,应该让你去(这个脚本是Safari浏览器)...

property these_URLs : {} 
set the text item delimeters of AppleScript to "" 
---------------------------------------------------------------------------------- 
--Initialize the program 
set the action to the button returned of (display dialog "Create or view a list of favorites..." buttons{"Cancel","View","Create"} default button 3) 
if the action is "Create" then 
    create_text_file() 
else 
    open_favorites() 
end if 

---------------------------------SUBROUTINES-------------------------------------- 

on create_text_file() 
    --get the URL of every tab of every window 
    tell application "Safari" 
     set theWindows to (get every document) as list 
     repeat with i from 1 to the count of theWindows 
      set this_Window to item i of theWindows 
      set theTabs to (get every tab of this_Window) as list 
      repeat with x from 1 to the count of theTabs 
       set this_Tab to item x of theTabs 
       set this_URL to (the URL of this_tab) as string 
       set the end of these_URLs to this_URL 
      end repeat 
     end repeat 
    end tell 

    --put the URLs into a text document 
    set newFile to (choose file name with prompt "Choose a name and location for the new file:" default location (path to desktop folder)) 
    try 
     open for access newFile with write permission 
     set the text item delimiters of AppleScript to return 
     set the_URLs to these_URLs as string 
     write the_URLS to file newFile 
     close access newFile 
    on error 
     try 
      close access newFile 
     end try 
    end try 
    set the text item delimiters of AppleScript to "" 
end create_text_file() 

on open_favorites() 
    --Verify whether you have saved any favorites with this script 
    if these_URLs is {} then display dialog "You have not added any favorites with this script." with icon note buttons{"Cancel"} 
    --there are favorites so open all the URLs you stored in the text file 
    repeat with i from 1 to the count of these_URLs 
     set this_URL to item i of these_URLs 
     tell application "Safari" to make new tab at the end of tabs of document 1 with properties {URL:this_URL} 
    end repeat 
end open_favorites 

如果您有任何问题,只是问。 :)

相关问题