15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu 18.04LTSとchromium-browser(Headless)とpython3でSeleniumする

Last updated at Posted at 2018-09-25

条件

  • Ubuntu 18.04.1 LTS (bionic)を使用する
  • Ubuntu標準リポジトリを使用する
  • Google Chromeはインストールしない
  • Chromium BrowserはHeadlessで使う
  • pip(pip3)は使わない(インストールしない)

必要なパッケージのインストール

# apt update && apt upgrade -y
# apt install chromium-browser
# apt install chromium-chromedriver
# apt install python3-selenium

サンプル

以下のコードを実行すると、Headless ChromiumでYahoo! Japanにアクセスし、body属性以下の文字列が結果としてprintされる。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1024,768')

driver = webdriver.Chrome(executable_path="/usr/lib/chromium-browser/chromedriver", chrome_options=options);
driver.implicitly_wait(600)


setup_url="https://www.yahoo.co.jp/"
driver.get(setup_url)
print(driver.find_element_by_xpath("//body").text)

driver.close()
15
20
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
15
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?