def
_get_car_info(
self
, _url:
str
):
res
=
self
._parse_url(_url
=
_url)
ret
=
res.text
result
=
etree.HTML(ret)
title
=
result.xpath(
'//div[@class="car-box"]/h3//text()'
)
title
=
title[
1
].strip()
if
len
(title) >
1
else
title[
0
].strip()
play_time
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[1]/text()'
)
play_time
=
play_time[
0
].strip()
if
play_time
else
'-'
display_mileage
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[2]/text()'
)
display_mileage
=
display_mileage[
0
].strip()
if
display_mileage
else
'-'
gearbox
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[3]/text()'
)
gearbox
=
gearbox[
0
].strip()
if
gearbox
else
'-'
emission_standards
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[4]/text()'
)
emission_standards
=
emission_standards[
0
].strip()
if
emission_standards
else
'-'
displacement
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[5]/text()'
)
displacement
=
displacement[
0
].strip()
if
displacement
else
'-'
release_time
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[1]/li[6]/text()'
)
release_time
=
release_time[
0
].strip()
if
release_time
else
'-'
annual_inspection_expires
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[2]/li[1]/text()'
)
annual_inspection_expires
=
annual_inspection_expires[
0
].strip()
if
annual_inspection_expires
else
'-'
insurance_expires
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[2]/li[2]/text()'
)
insurance_expires
=
insurance_expires[
0
].strip()
if
insurance_expires
else
'-'
warranty_expires
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[2]/li[3]/text()'
)
warranty_expires
=
warranty_expires[
0
].strip()
if
warranty_expires
else
'-'
number_of_transfers
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[2]/li[5]/text()'
)
number_of_transfers
=
number_of_transfers[
0
].strip()
if
number_of_transfers
else
'-'
location
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[2]/li[6]/text()'
)
location
=
location[
0
].strip()
if
location
else
'-'
engine
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[3]/li[1]/text()'
)
engine
=
engine[
0
].strip()
if
engine
else
'-'
vehicle
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[3]/li[2]/text()'
)
vehicle
=
vehicle[
0
].strip()
if
vehicle
else
'-'
car_color
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[3]/li[3]/text()'
)
car_color
=
car_color[
0
].strip()
if
car_color
else
'-'
fuel_label
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[3]/li[4]/text()'
)
fuel_label
=
fuel_label[
0
].strip()
if
fuel_label
else
'-'
drive_mode
=
result.xpath(
'//*[@id="nav1"]/div[1]/ul[3]/li[5]/text()'
)
drive_mode
=
drive_mode[
0
].strip()
if
drive_mode
else
'-'
data
=
[[title, play_time, display_mileage, gearbox, emission_standards, displacement, release_time, annual_inspection_expires,
insurance_expires, warranty_expires, number_of_transfers, location, engine, vehicle, car_color, fuel_label, drive_mode, _url]]
print
(data)
self
._save_csv(data
=
data)