2016-08-10 1 views
0

スクリプトを作成しようとしています。これにより、Chromeの内部ページ内の文字列を検索できます(例: "chrome:// help ")。
これは簡単な方法ですか(Selenium webdriver APIのような)特別なツールが必要ですか?
「通常の」Webページで使用することは可能ですが、「内部」のWebページはどうですか?PythonとまたはSeleniumを使用してクロムの内部ページ内の文字列を検索する方法

答えて

1

selenium Webdriverを使用すると簡単にこのタスクを実行できます。この場合、Google Chromeのバージョン番号を抽出します。ここで

は、すべての工程を説明するコメントとサンプルコードです:

from selenium import webdriver 

# executable path should be the place where chrome driver is on the computer 

driver = webdriver.Chrome(executable_path= '/users/user/Downloads/Chromedriver') 

# This line tells the driver to go to the help section of chrome 

driver.get('chrome://help') 

# Because certain elements are stored in another Iframe, you must switch to this particular Iframe which is called 'help' in this case. 

driver.switch_to.frame(driver.find_element_by_name('help')) 

# retrive the text of the element and store it's text in a variable. 

version_string = driver.find_element_by_id('version-container').text 

# Now you can easily print it. 

print version_string 
関連する問題