Chrome 122.0.6261.95
Chrome driver 122.0.6261.94
Python 3.8.3
If I comment out option.add_argument("--headless=new"), it will print(len(elements)) will print 2. Otherwise, can not print anything. Thanks a lot
import time
import subprocess
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
import pandas as pd
#from playsound import playsound
import datetime
import threading
service = Service(executable_path='chromedriver.exe')
option = webdriver.ChromeOptions()
option.add_argument("--headless=new")
option.add_argument('--ignore-certificate-errors')
option.add_argument("--no-sandbox")
option.add_argument('disable-notifications')
driver = webdriver.Chrome(service=service,options=option)
def search(dep,arr,date):
print(f'''Input: Date:{date},Departure: {dep} - Arrival: {arr}''')
base_url = f'https://www.kayak.com/flights/SFO-PEK/2024-03-06?sort=price_a&fs=stops=0'
print("before webdriver.ChromeOptions()")
my_url = base_url
driver.get(my_url)
print(my_url)
time.sleep(10) # set the time to wait till web fully loaded
# Find all elements with class "nrc6"
elements = driver.find_elements(By.CLASS_NAME, "nrc6")
# Print the number of elements found
print(len(elements))