Вот работающий без головы код < /p>
Код: Выделить всё
# _-_-_- Non Headless -_-_-_
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import webbrowser
def GetFAAapdURL(APD):
driver = webdriver.Chrome()
driver.get("https://www.faa.gov/airports/runway_safety/diagrams/")
input_field = driver.find_element(By.ID, "ident") # Replace with actual ID
input_field.send_keys(APD)
input_field.send_keys(Keys.RETURN)
table = driver.find_element(By.XPATH, "//table") # Adjust XPath as needed
links = table.find_elements(By.TAG_NAME, "a")
for link in links:
href = link.get_attribute("href")
if href: # Ensure the href is not None
if "aeronav.faa" in href:
print(href)
return href
webbrowser.open(GetFAAapdURL("ATL"))
# _-_-_- Headless -_-_-_
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import webbrowser
def GetFAAapdURL_Headless(APD):
chrome_options = Options()
chrome_options.add_argument("--headless") # Run Chrome in headless mode
chrome_options.add_argument('--window-size=1920x1080')
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.faa.gov/airports/runway_safety/diagrams/")
input_field = driver.find_element(By.ID, "ident")
input_field.send_keys(Keys.RETURN)
table = driver.find_element(By.XPATH, "//table") # Adjust XPath as needed
links = table.find_elements(By.TAG_NAME, "a")
for link in links:
href = link.get_attribute("href")
if href: # Ensure the href is not None
if "aeronav.faa" in href:
print(href)
return href
webbrowser.open(GetFAAapdURL_Headless("ATL"))
< /code>
Вот линия, что ошибки < /p>
input_field = driver.find_element(By.ID, "ident")
< /code>
Я попытался свести к минимуму окно, и у него есть мигание окна при начале и все еще ошибках. Так что не отличное решение.
Подробнее здесь: https://stackoverflow.com/questions/797 ... d-while-us