下記サイトにchromedriverとseleniumを用いてアクセスしようと試みています。
他のサイトでは問題なくアクセスできていますが、getで処理が止まってしまいます。
【環境】
Ubuntu 22.04.3 LTS
Python 3.10.12
Google Chrome 116.0.5845.110
Selenium 4.14.0
import sys
sys.dont_write_bytecode = True
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from time import sleep
import time
CHROMEDRIVER = "/usr/bin/chromedriver"
if __name__ == '__main__':
url = "https://salonboard.com/login"
service = Service(executable_path=CHROMEDRIVER)
#ヘッドレスモードでブラウザを起動
options = Options()
options.add_argument('--headless')
options.add_argument("--no-sandbox")
#ブラウザを起動
driver = webdriver.Chrome(service=service, options=options)
# urlにアクセス
print('before get')
driver.set_page_load_timeout(30)
try:
driver.get(url)
print('after get')
except Exception as e:
print('timeout')
finally:
#ブラウザ停止
driver.quit()
【出力】
before get
timeout
options.add_argument('--headless')
を外すとまた別のエラーメッセージは出ますが処理は進むようですね。options.add_argument('--user-agent="Mozilla.途中省略."')
を指定してみてはどうでしょう? 同様に別のエラーメッセージは出ますが処理は進むようです。最初のコメントも含めてどちらもWindows上で試しているので状況は違うかもしれませんが。