How to retrieve html source from the web application WindGuru

后端 未结 1 574
借酒劲吻你
借酒劲吻你 2021-01-21 18:02

It\'s only happen when I use the headless mode.

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument(\'--headless\')

driver          


        
1条回答
  •  遥遥无期
    2021-01-21 18:56

    You were almost there. You simply need to induce WebDriverWait for the desired element to be visible and you can use the following solution:

    • Code Block:

      from selenium import webdriver
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      
      options = webdriver.ChromeOptions()
      options.add_argument('--headless')
      options.add_argument("start-maximized")
      options.add_argument("disable-infobars")
      options.add_argument("--disable-extensions")
      driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      driver.get('https://www.windguru.cz/3640')
      WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#forecasts-page")))
      print(driver.page_source)
      driver.quit() 
      
    • Console Output:

      
      Windguru - Argentina - Mar del Plata
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

    0 讨论(0)
提交回复
热议问题