忍者ブログ
Admin / Write / Res
ちゃんとカテゴリ分けされておりませんので、 記事をお探しならブログ内検索が便利です。 ご活用くださいませー+.(≧∀≦)゚+.゚
ブログ内検索
カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
カウンター
アクセスカウンター
最新コメント
[04/05 Fully Vaccinated Adorable Escort Service in bengaluru 8273600238]
[03/26 Tonaldcet]
[01/16 jilibet]
[10/20 Call Girl in Delhi]
[09/07 לפרטים נוספים]
最新トラックバック
プロフィール
+ハンドル+
y_ayamori(purple)
+職業+
IT系エンジニア
+すまい+
さいたま
バーコード
[703]  [702]  [701]  [700]  [699]  [698]  [697]  [696]  [695]  [694]  [692
pythonのseleniumでWEBのテストを行う方法です。
Firefoxに関する記事はいっぱいあるし、特にseleniumさえ導入できればすぐに使えるので問題ないのですが、Chromeになると情報が少ないので載せておきます。

大前提としてChromeさんをインストールしておいてね。

次に、ドライバをインストール。
zipを解凍して出てくる「chromedriver.exe」を任意のディレクトリに配置します。

前支度はこれくらい。
意外と簡単でした。

ユーザエージェントとプロキシを変更して、ハンドリングする場合のサンプルを掲載しておきます。

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--user-agent=Mozilla/5.0 (Linux; Android 4.2.2; SHL24 Build/S2040) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36")
options.add_argument("--proxy-server=localhost:8080")
options.add_argument("--disable-prompt-on-repost")
driver = webdriver.Chrome(r'C:\chromedriver.exe', chrome_options=options) 
driver.get("https://www.google.co.jp/")

add_argument()はおそらくみたとおり、chrome.exeの起動オプションがそのまま使えそうです。


参考文献
http://www.ericdlarson.com/misc/chrome_command_line_flags.html
http://www.mazn.net/blog/2014/07/08/1371.html
http://yuichi.tea-nifty.com/blog/2008/12/googlechrome-c0.html
http://www.yoheim.net/blog.php?q=20130402

拍手

PR
この記事にコメントする
Name
Title
Color
Mail
URL
Comment
Password   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
secret (管理人にのみ表示)
Copyright ©  アナログを愛するデジタル生活館 All Rights Reserved.
* material by Pearl Box   * Template by tsukika

忍者ブログ [PR]