Netscape Navigator — это веб-браузер, популярный на заре Интернета. Вот несколько методов, которые вы можете использовать с примерами кода для выполнения различных задач, связанных с веб-браузерами:
-
Запустите Netscape Navigator с помощью Python:
import webbrowser url = 'http://www.example.com' webbrowser.get('netscape').open(url)
-
Сделать снимок экрана веб-страницы в Netscape Navigator с помощью Python:
import time from selenium import webdriver # Set the path to the Netscape Navigator executable path_to_navigator = 'C:/Program Files/Netscape Navigator/navigator.exe' # Configure the webdriver options = webdriver.FirefoxOptions() options.binary_location = path_to_navigator driver = webdriver.Firefox(executable_path='geckodriver', options=options) # Open the webpage url = 'http://www.example.com' driver.get(url) # Wait for the page to load time.sleep(5) # Capture a screenshot driver.save_screenshot('screenshot.png') # Close the browser driver.quit()
-
Извлечение HTML-содержимого веб-страницы с помощью Python и Beautiful Soup с помощью Netscape Navigator:
import requests from bs4 import BeautifulSoup url = 'http://www.example.com' headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Netscape/9.0.0.6'} response = requests.get(url, headers=headers) soup = BeautifulSoup(response.content, 'html.parser') # Extract specific elements from the HTML title = soup.title.text paragraphs = soup.find_all('p') # Print the extracted data print('Page Title:', title) print('Paragraphs:') for p in paragraphs: print(p.text)