WSH 関連

Internet Explorer の自動化

はてなブックマークの登録処理の自動化

  • はてなブックマークの登録処理の自動化
    ' AddBookmark.vbs
    ' Usage : CScript AddBookmark.vbs
    ' <処理概要>
    ' 1. お気に入りフォルダの取得
    ' 2. お気に入りの URL を取得
    ' 3. お気に入りの URL を Internet Explorer で表示
    ' 4. 表示された URL を「はてなブックマーク」に登録
    ' 5. Internet Explorer を閉じる
    ' 6. 2〜5 の繰り返し
    ' 
    
    Option Explicit
    
    Main
    
    Sub Main
        Dim nResult
        nResult = MsgBox( "はてなブックマークへの一括登録処理を行います。", vbOKCancel, "確認" )
        If nResult <> vbOK Then
            ' OK 以外の場合、処理を抜けます。
            Exit Sub
        End If
        
        ' お気に入りのブックマークの一括登録処理
        ' ↓ 処理を有効にする場合、以下のコメントを外してください。
        ' AddBookmarkFromFavorites
        
        ' 指定した URL のリストの一括登録処理
        ' ↓ 処理を有効にする場合、以下のコメントを外してください。
        ' AddBookmarkFromList
        
        ' 処理の終了
        MsgBox "はてなブックマークへの登録処理を完了しました。", vbOKOnly, "終了"
    End Sub
    
    Sub AddBookmarkFromList
        Dim dic
        Set dic = CreateObject("Scripting.Dictionary")
        
        ' ↓登録したい URL をここに記述
        dic.Add "http://www.hatena.ne.jp/1108104573", ""
        dic.Add "http://www.hatena.ne.jp/1108213360", ""
        dic.Add "http://www.hatena.ne.jp/1108215897", ""
        dic.Add "http://www.hatena.ne.jp/1108438733", ""
        
        ' リストの内容をブックマークとして登録
        AddBookmarks dic
    End Sub
    
    Sub AddBookmarkFromFavorites
        Dim dic
        Set dic = CreateObject("Scripting.Dictionary")
        
        ' お気に入りの情報を取得
        RetrieveFavorites dic
    
        ' リストの内容をブックマークとして登録
        AddBookmarks dic
    End Sub
    
    Function RetrieveFavorites( dic )
        Dim shell
        Set shell = CreateObject("Shell.Application")
        
        Dim folder
        Set folder = shell.NameSpace(6) ' お気に入りフォルダ
        
        FavoritesToDictionary folder, dic
    End Function
    
    Function FavoritesToDictionary( folder, dic )
        Dim wsh
        Set wsh = CreateObject("WScript.Shell")
        
        ' サブディレクトリも対象とする
        Dim item
        For Each item In folder.Items
            If item.IsFolder Then
                FavoritesToDictionary item.GetFolder, dic
            ElseIf item.IsLink Then
                Dim link
                Set link = wsh.CreateShortcut( item.Path )
                ' お気に入りの URL の登録情報を取得
                dic.Add link.TargetPath, item.Name
            End If
        Next
    End Function
    
    Function AddBookmarks( dicURL )
        Dim strURL
        ' データ件数分ループ
        For Each strURL In dicURL
            AddBookmark strURL
        Next
    End Function
    
    Function AddBookmark( strURL )
        Dim objIE
        Set objIE = CreateObject("InternetExplorer.Application")
        
        ' IE の画面を表示させたくない場合は False をセットしてください
        objIE.Visible = True
        
        ' ページロード&タイトル取得
        objIE.Navigate strURL ' ページの読み込み
        While ( objIE.Busy ) : WScript.Sleep 100 : Wend
        Dim strTitle
        strTitle = objIE.Document.Title
        
        ' はてなブックマークの登録処理
        Dim strCGI
    '    strCGI = "http://b.hatena.ne.jp/add?mode=confirm&url=" & Escape(strURL)
        strCGI = "http://b.hatena.ne.jp/add?mode=confirm&title=" & Escape(strTitle) & "&url=" & Escape(strURL)
        objIE.Navigate strCGI ' 登録画面の呼び出し
        While ( objIE.Busy ) : WScript.Sleep 100 : Wend
        objIE.Document.Forms(0).commit.Click ' 追加するボタンをクリック
        While ( objIE.Busy ) : WScript.Sleep 100 : Wend
    
        objIE.Quit
        Set objIE = Nothing
        
        ' 念のためウェイトを入れておく
        WScript.Sleep 1000
    End Function
  • 動作保証は致しかねます。実行は自己責任でお願いします。

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2010-02-27 (土) 14:19:09 (5586d)