Google Chromeのインストール
1 2 3 4 5 6 7 8 9 10 11 |
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb --2023-03-05 10:01:20-- https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb Resolving dl.google.com (dl.google.com)... 2404:6800:400a:805::200e, 142.250.207.110 Connecting to dl.google.com (dl.google.com)|2404:6800:400a:805::200e|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 94023644 (90M) [application/x-debian-package] Saving to: ‘google-chrome-stable_current_amd64.deb’ google-chrome-stable_current 100%[============================================>] 89.67M 8.89MB/s in 10s 2023-03-05 10:01:30 (8.81 MB/s) - ‘google-chrome-stable_current_amd64.deb’ saved [94023644/94023644] |
1 2 3 4 5 6 7 8 |
$ sudo dpkg -i google-chrome-stable_current_amd64.deb (Reading database ... 150096 files and directories currently installed.) Preparing to unpack google-chrome-stable_current_amd64.deb ... Unpacking google-chrome-stable (110.0.5481.177-1) over (110.0.5481.177-1) ... Setting up google-chrome-stable (110.0.5481.177-1) ... Processing triggers for mailcap (3.70+nmu1ubuntu1) ... Processing triggers for desktop-file-utils (0.26-1ubuntu3) ... Processing triggers for man-db (2.10.2-1) ... |
1 2 |
$ google-chrome-stable --version Google Chrome 110.0.5481.177 |
よくわからないけど、最初エラーがでてきたけど以下をやってなくなった。
1 2 |
$ sudo apt install libu2f-udev/jammy $ sudo apt --fix-broken install |
seleniumインストール
1 2 |
$ sudo apt -y install python3-pip $ pip install selenium |
実行
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 31 32 33 34 35 36 37 38 39 40 |
# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.chrome.options import Options CHROMEDRIVER = "/usr/local/bin/chromedriver" def get_driver(init_flg): # ヘッドレスモードでブラウザを起動 options = Options() options.add_argument('--headless') # ブラウザーを起動 driver = webdriver.Chrome(CHROMEDRIVER, options=options) return driver if __name__ == '__main__': url = "https://example.com/" # ヘッドレスモードでブラウザを起動 options = Options() options.add_argument('--headless') # ブラウザーを起動 driver = webdriver.Chrome(CHROMEDRIVER, options=options) # urlにアクセス data = driver.get(url) print(driver.page_source) title = driver.find_element_by_tag_name("h1") print(title.text) # ブラウザ停止 driver.quit() |
1 |
$ python3 hoge.php |