32bit LinuxでSelenium
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
* 32bit LinuxでSelenium [#o3bb5e76]
ラズパイでSeleniumが動作したので気を良くして32bit Linuxで...
** セットアップの準備 [#hde8718f]
$ sudo apt update
$ sudo apt upgrade
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
$ uname -a
Linux debian 5.10.0-10-686-pae #1 SMP Debian 5.10.84-1 (...
** python環境 [#ueaf06fb]
今回はpython3で導入(Debian 32bitの標準環境はpython2.7)
$ sudo apt install -y python3 python3-pip
$ python3 -V
Python 3.9.2
** selenium の導入 [#i3ac78f7]
selenium の導入(バージョン指定をせずに導入すると selenium...
$ pip3 install selenium
ここでエラーが発生。 build-essential は導入済みだったが R...
$ sudo apt install curl
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup...
info: downloading installer
Welcome to Rust!
== 途中省略 ==
Current installation options:
default host triple: i686-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
== 途中省略 ==
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to incl...
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source $HOME/.cargo/env
そのまま[リターン]で i686-unknown-linux-gnu を選択。~
実は、openssl も必要ということで
$ sudo apt install -y libssl-dev
さっきの selenium 導入失敗時に upgrade しろって言われたみ...
$ pip install --upgrade pip
ようやく仕切り直しで
$ pip3 install selenium
$ pip3 list | grep selenium
selenium 4.1.0
** geckodriver の導入 [#b36ba887]
chromium-chromedriver が導入できないようなので、代わりに ...
まずは、Firefox ESR の導入。
$ sudo apt install firefox-esr-l10n-ja
$ firefox --version
Mozilla Firefox 91.6.0esr
geckodriver の導入は手作業。
$ wget https://github.com/mozilla/geckodriver/releases/d...
$ tar -zxvf geckodriver-v0.30.0-linux32.tar.gz
$ sudo mv geckodriver /usr/bin/geckodriver
$ sudo chown root:root /usr/bin/geckodriver
$ sudo chmod +x /usr/bin/geckodriver
** ソースコード(selenium_by_geckodriver.py) [#wb974dde]
ラズパイと同じことをここでも
#highlight(python){{
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
# ブラウザをヘッドレスで起動するためのオプション指定
options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(options=options)
# Googleのトップ画面を開く
driver.get('https://www.google.co.jp/')
# 画面表示を最大5秒待つ
driver.implicitly_wait(5)
# 検索語を入力する
input_element = driver.find_element(By.NAME, 'q')
input_element.send_keys('Raspberry Pi' + Keys.RETURN)
# 検索結果が出るまでちょっと待つ
time.sleep(3)
# スクリーンショットを保存する
driver.save_screenshot('google.png')
# ブラウザを終了する
driver.close()
}}
#highlight(end)
#ref(selenium_by_geckodriver.py)
** 実行 [#e675736e]
$ python3 selenium_by_geckodriver.py
#htmlinsert(amazon_pc.html);
終了行:
* 32bit LinuxでSelenium [#o3bb5e76]
ラズパイでSeleniumが動作したので気を良くして32bit Linuxで...
** セットアップの準備 [#hde8718f]
$ sudo apt update
$ sudo apt upgrade
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
$ uname -a
Linux debian 5.10.0-10-686-pae #1 SMP Debian 5.10.84-1 (...
** python環境 [#ueaf06fb]
今回はpython3で導入(Debian 32bitの標準環境はpython2.7)
$ sudo apt install -y python3 python3-pip
$ python3 -V
Python 3.9.2
** selenium の導入 [#i3ac78f7]
selenium の導入(バージョン指定をせずに導入すると selenium...
$ pip3 install selenium
ここでエラーが発生。 build-essential は導入済みだったが R...
$ sudo apt install curl
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup...
info: downloading installer
Welcome to Rust!
== 途中省略 ==
Current installation options:
default host triple: i686-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
== 途中省略 ==
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to incl...
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source $HOME/.cargo/env
そのまま[リターン]で i686-unknown-linux-gnu を選択。~
実は、openssl も必要ということで
$ sudo apt install -y libssl-dev
さっきの selenium 導入失敗時に upgrade しろって言われたみ...
$ pip install --upgrade pip
ようやく仕切り直しで
$ pip3 install selenium
$ pip3 list | grep selenium
selenium 4.1.0
** geckodriver の導入 [#b36ba887]
chromium-chromedriver が導入できないようなので、代わりに ...
まずは、Firefox ESR の導入。
$ sudo apt install firefox-esr-l10n-ja
$ firefox --version
Mozilla Firefox 91.6.0esr
geckodriver の導入は手作業。
$ wget https://github.com/mozilla/geckodriver/releases/d...
$ tar -zxvf geckodriver-v0.30.0-linux32.tar.gz
$ sudo mv geckodriver /usr/bin/geckodriver
$ sudo chown root:root /usr/bin/geckodriver
$ sudo chmod +x /usr/bin/geckodriver
** ソースコード(selenium_by_geckodriver.py) [#wb974dde]
ラズパイと同じことをここでも
#highlight(python){{
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
# ブラウザをヘッドレスで起動するためのオプション指定
options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(options=options)
# Googleのトップ画面を開く
driver.get('https://www.google.co.jp/')
# 画面表示を最大5秒待つ
driver.implicitly_wait(5)
# 検索語を入力する
input_element = driver.find_element(By.NAME, 'q')
input_element.send_keys('Raspberry Pi' + Keys.RETURN)
# 検索結果が出るまでちょっと待つ
time.sleep(3)
# スクリーンショットを保存する
driver.save_screenshot('google.png')
# ブラウザを終了する
driver.close()
}}
#highlight(end)
#ref(selenium_by_geckodriver.py)
** 実行 [#e675736e]
$ python3 selenium_by_geckodriver.py
#htmlinsert(amazon_pc.html);
ページ名: