from selenium import webdriver
from bs4 import BeautifulSoup
from datetime import datetime
defget_car_names(url):# Set up the Selenium WebDriver (make sure to have the appropriate WebDriver for your browser)
driver = webdriver.Chrome()try:# Load the webpage using Selenium
driver.get(url)# Wait for some time to allow JavaScript to execute and load dynamic content
driver.implicitly_wait(10)# Get the page source after JavaScript execution
page_source = driver.page_source
# Parse the HTML content
soup = BeautifulSoup(page_source,'html.parser')# Extract car names from anchor elements with class="series-card_name__3QIlf" and rel="opener"
car_names =[]for anchor_element in soup.find_all('a', class_='series-card_name__3QIlf', rel='opener'):
car_name = anchor_element.text.strip()
car_names.append(car_name)return car_names
finally:# Close the browser window
driver.quit()# Example usage
url ='https://www.dongchedi.com/auto/library/80,!1-x-x-x-x-x-x-x-x-x-x-x-13-x-x-x-x-x'
car_names = get_car_names(url)if car_names:for rank, name inenumerate(car_names, start=1):print(f"Rank: {rank}, Car Name: {name}")