LoginSignup
2
3

More than 5 years have passed since last update.

Pywin32 事始め

Last updated at Posted at 2018-09-06

インストール

$ python -m pip -V
pip 10.0.1 from C:\Users\[username]\AppData\Local\Programs\Python\Python37\lib\site-packages\pip (python 3.7)

$ python -m pip freeze

$ python -m pip list
Package    Version
---------- -------
pip        10.0.1
setuptools 39.0.1

$ pip install pywin32
Collecting pywin32
  Downloading https://files.pythonhosted.org/packages/f4/fb/ba9e519d90b63090005bcdee900d318d895d475c627dc1bc0f77b27abad0/pywin32-223-cp37-cp37m-win_amd64.whl (8.9MB)
    100% |████████████████████████████████| 8.9MB 4.5MB/s
Installing collected packages: pywin32
Successfully installed pywin32-223

$ pip list
Package    Version
---------- -------
pip        10.0.1
pywin32    223
setuptools 39.0.1

参考

操作

サンプルコードを実行
http://catech6ler.hatenadiary.jp/entry/2016/03/22/101932

操作:ブラウザ(selenium)


$ pip install selenium
Collecting selenium
  Downloading https://files.pythonhosted.org/packages/b8/53/9cafbb616d20c7624ff31bcabd82e5cc9823206267664e68aa8acdde4629/selenium-3.14.0-py2.py3-none-any.whl (898kB)
    100% |████████████████████████████████| 901kB 6.8MB/s
Collecting urllib3 (from selenium)
  Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 9.3MB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.14.0 urllib3-1.23

chromedriver.exeを以下のフォルダに格納

C:\Users\masaaki\AppData\Local\Programs\Python\Python37

プログラム


$ vi test.py
# -*- coding: utf-8 -*-
# seleniumのwebdriverをインポート
from selenium import webdriver
# chromeを開く
chro = webdriver.Chrome()
# urlを指定する
chro.get("https://yahoo.co.jp/")
# chrome閉じる
chro.quit()

$ python ./test.py

参考

https://toolmania.info/post-9657/
https://sites.google.com/a/chromium.org/chromedriver/downloads

操作:ブラウザ(webbrowser)

プログラム


$ vi test.py
# -*- coding: utf-8 -*-

import webbrowser
webbrowser.open('https://tonari-it.com/')

$ python ./test.py
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3