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
ctagsについて
id:Voluntasさんからtwitterで教えてもらったツールを調べてみた。
ctagsとは
Ctagsは、テキスト・エディタやその他のユーティリティで、 (プログラミング言語で記述された)ソース・ファイル中のオブジェクト定義をすばやく簡単に検索するためのインデックス(または tag)を生成するためのツールです。 tagは、プログラミング言語で定義されるもののうちインデックスとして取得可能なオブジェクト(あるいはオブジェクト用に生成されたインデックスのエントリ) を示します。
http://hp.vector.co.jp/authors/VA025040/ctags/
お〜!!最初はなかなかイメージできなかったけど、MSのVisualStudioに近づけそう。。。
さらに調べると便利そうなものも発見!!(もう当たり前だったりするのかな。。。:-))
http://d.hatena.ne.jp/guyon/20080409/1207737955
http://vim.sourceforge.net/scripts/script.php?script_id=2179
ちょっと使い込んでみます。Vimはぺーぺーくんなので。。。(T T)
今日の気になったモジュール
こんなシリーズを続けてみようかな。。。
- DyanamicDNSクライアント(自分でHP作るときに。。。)
http://jumbo.narod.ru/src/DNS.py
- DyanamicDNSクライアント (こっちのほうが有名?)
- Python VirtualBox API (VirualBox派です。)
http://enomalism.com/api/pyvb/
- Python SpreadSheet(イチオシ?)
http://sourceforge.net/projects/pyspread
GenshiでSpreadSheetとかあるんだろうか?