pywinautoのExample3 FireFoxでWEBサイトを保存してみる

ショートカットキーの使い方。

#coding: utf-8
# -*- encoding: utf-8 -*- 
import sys, locale, codecs

enc = locale.getpreferredencoding()
sys.stdout = codecs.getwriter(enc)(sys.stdout)
sys.stdin = codecs.getreader(enc)(sys.stdin)

from pywinauto.application import Application
import time
import os.path

from pywinauto import WindowAmbiguousError

if len(sys.argv) < 2:
    print "please specify a web address to download"
    sys.exit()

web_addresss = sys.argv[1]

if len(sys.argv) > 2:
    outputfilename = sys.argv[2]
else:
    outputfilename = web_addresss
    outputfilename = outputfilename.replace('/', '')
    outputfilename = outputfilename.replace('\\', '')
    outputfilename = outputfilename.replace(':', '')
    if not (outputfilename.lower().endswith("htm") or
       outputfilename.lower().endswith("html")):
       outputfilename += ".html"

# make sure that we have an absolute path - otherwise it is
# hard to know where firefox might save the file!
outputfilename = os.path.abspath(outputfilename)

# start IE with a start URL of what was passed in
app = Application().start_(
    r"c:\program files\Mozilla Firefox\Firefox.exe %s"% web_addresss)

# some pages are slow to open - so wait some seconds
time.sleep(4)

# mozilla is one of thos applications that use existing windows
# if they exist (at least on my machine!)
# so if we cannot find any window for that process
#  - find the actual process
#  - connect to it
if app.windows_():
    mozilla =  app.window_(title_re = ".*Mozilla Firefox")

else:
    app = Application().connect_(title_re = ".*Mozilla Firefox")
    mozilla = app.window_(title_re = ".*Mozilla Firefox")

# ie doesn't define it's menus as Menu's but actually as a toolbar!
print "No Menu's in FireFox:", mozilla.MenuItems()

# File -> Save As
#mozilla.TypeKeys("%FA") #なぜかうまくいかないことがあるので、分けてみる。。。
mozilla.TypeKeys("%F")
mozilla.TypeKeys("%A")

#ie.Toolbar3.PressButton("File")

app.Dialog.Edit.SetEditText(outputfilename)

app[u"名前を付けて保存"][u"保存"].CloseClick()

try:
    # if asked to overwrite say yes
    if app[u"名前を付けて保存"][u"はい"].Exists():
        app[u"名前を付けて保存"][u"はい"].CloseClick()
except WindowAmbiguousError, e:
    for w in e.windows:
        w = HwndWrapper(w)
        print w.WindowText(), w.Class()

print "saved:", outputfilename

# File close tab or close
#(Firefox makes it easy for us having the same shortcut for both!
mozilla.TypeKeys("%FC")
python ファイル名 webアドレス

でWEBサイトを保存します。

そろそろexamplesでお伝えすることが減ってきたので、どなかたこのアプリをこういう風に自動化してみて!!というのありませんか?
お金のかかる(購入しないといけない)アプリは無理ですが。。。orz
(持ってれば対応しますです。:-)
win32アプリでお願いします。m(_ _)m