We use Selenium for web scraping. At the time of development, I forgot to ask, "What? How do you write this?", And decided to cover only the items I'm investigating in this article.
ChromeOptions In rare cases, the following timeout error will occur if the required options are not set.
Timed out receiving message from renderer: 600.000
About this, Stack Overflow Answerでは、以下のオプション設定を行えば問題ないそうです。(ちなみに「役に立たない増え続ける引数オプション」と呼ばれており、まさにその通り・・・)
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
The WebDriverWait.until method allows you to set an explicit wait time for any HTML element to wait for a particular state. Click here for details (https://kurozumi.github.io/selenium-python/api.html#module-selenium.webdriver.support.expected_conditions).
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "cnfm_btn")))
WebDriverWait(driver, 10).until(EC.element_located_to_be_selected((By.ID, "cnfm_btn")))
Recommended Posts