2008-11-18 17 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 

如果您有任何問題,只是問。 :)

相關問題