我需要从车辆中提取信息很多次,这些信息会出现在搜索中,现在我总是使用此代码,并且需要能够转到下一个
网址为:link
numberCars = len(driver.find_elements_by_xpath("//tr[contains(@class, 'carResultRow_CarDetails')]"))
for i in range(numberCars):
Page = BeautifulSoup(driver.page_source, 'html.parser')
Currency = Page.find('span', {'class': 'carResultRow_Price-now'})
Date = Page.find('span', 'carResultRow_Price-duration')
vehicle_model = driver.find_element_by_css_selector("td.carResultRow_CarSpec>h2")
for each_div in Page.findAll('div','search-summary__date'):
print(each_div)
答案 0 :(得分:0)
这是给你的主意,我敢肯定你会明白你在做错什么。
您正在遍历错误的事物。
from selenium import webdriver
from bs4 import BeautifulSoup
url = '<your url>'
driver = webdriver.Chrome()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html)
rows = soup.select('.carResultRow_CarDetails') # select all car rows in the page
for row in rows:
# Get price, you can get more details in similar manner.
Price = row.find('span', {'class': 'carResultRow_Price-now'})
print(Price.text)
输出:
US$141.21
US$150.92
US$173.79
US$191.07
US$228.67
US$248.61
US$251.53
US$283.55