Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
19
Help us understand the problem. What is going on with this article?
@tabimoba

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

More than 1 year has passed since last update.

条件

  • 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()
19
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
19
Help us understand the problem. What is going on with this article?