Search code examples
pythonselenium-webdriverselenium-chromedriverheadless

how to get texts of elements with selenium in headless mode


I'm tiring to use selenium I headless mode (which works in background and won't open a tab in browser) my code finds elements but won't show any of texts between tags. any suggestions?

this is the code:

        options = Options()
        options.add_argument('--headless')
        options.add_argument('--disable-dev-shm-usage')
        options.add_argument('--disable-extensions')
        options.add_argument('--disable-sandbox')

        driver=webdriver.Chrome(Google_Chrome_Webdriver_Path, options=options)

        driver.get(Resource_Path)
        Search_Results=self.search_resorce_page(driver)

        for Search_Result in Search_Results:
            print(Search_Result.text , "\n")

Solution

  • i did it:

    from bs4 import BeautifulSoup
    
           .
           .
           .
    
            driver.get(Resource_Path)
            page_source=driver.page_source
            soup=BeautifulSoup(page_source,'html.parser')