-
Notifications
You must be signed in to change notification settings - Fork 1
/
KSL_Detail.py
138 lines (117 loc) · 4.33 KB
/
KSL_Detail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from selenium.webdriver.common.by import By
class KSL_Detail(object):
def __init__(self, driver, link):
self.link = link.get_attribute('href')
self.driver = driver
link.click()
self.year = ""
self.make = ""
self.model = ""
self.trim = ""
self.body = ""
self.cab_type = ""
self.bed = ""
self.e_condition = ""
self.i_condition = ""
self.drive_type = ""
self.dealer_licence = ""
self.stock_id = ""
self.transmission = ""
self.liters = ""
self.cylinders = ""
self.fuel_type = ""
self.doors = ""
self.belts = ""
self.mileage = ""
self.vin = ""
self.title = ""
self.exterior = ""
self.interior = ""
self.comments = self.findComments()
self.findAttributes()
self.driver.back()
def findAttributes(self):
buttonClass = "seeMore"
attPath = "//div[@class='top']/div/dl/dd"
seeMore = self.driver.find_element(By.CLASS_NAME, buttonClass)
if seeMore is not None:
seeMore.click()
"//div[@class='MuiGrid-root jss144']/p"
attElems = self.driver.find_elements(By.XPATH, attPath)
self.trim = attElems[0].text
self.transmission = attElems[1].text
self.engine = attElems[2].text
self.doors = attElems[3].text
self.stock_id = attElems[4].text
self.exterior = attElems[5].text
self.interior = attElems[6].text
self.certified = attElems[7].text
self.vin = attElems[8].text
def findComments(self):
commentPath = "//span/p"
return self.driver.find_element(By.XPATH, commentPath).text
def findFeatures(self):
features = []
featurePath = "//div[@class='feature-area']/ul/li"
featureElems = self.driver.find_elements(By.XPATH, featurePath)
for elem in featureElems:
features.append(elem.text)
return features
# CONVERT TO STRING
def __str__(self):
"""
Convert Detail object to string
:return: (string) Formatted string to display car data
"""
output = str(self.link.get_attribute('href')) + \
"\nYear: " + self.year + \
"\nMake: " + self.make + \
"\nModel: " + self.model + \
"\nTrim: " + self.trim + \
"\nBody: " + self.body + \
"\nCabin Type: " + self.cab_type + \
"\nTruck Bed: " + self.bed + \
"\nExterior Condition: " + self.e_condition + \
"\nInterior Condition: " + self.i_condition + \
"\nDrive Type: " + self.drive_type + \
"\nDealer Licence: " + self.dealer_licence + \
"\nStock Number: " + self.stock_id + \
"\nLiters: " + self.liters + \
"\nCylinders: " + self.cylinders + \
"\nFuel Type: " + self.fuel_type + \
"\nDoors: " + self.doors + \
"\nBelts: " + self.belts + \
"\nMileage: " + self.mileage + \
"\nVin: " + self.vin + \
"\nTitle type: " + self.title + \
"\nExterior Color: " + self.exterior + \
"\nInterior Color: " + self.interior
return output
# CONVERT TO DICTIONARY FOR CSV
def toDict(self):
"""
Convert Detail object to dict
:return: (dict) where keys are key details about the car and values are their values as strings
"""
# missing year, make, model, and mileage because they are redundant
return {
"Link": str(self.link.get_attribute('href')),
"Trim": self.trim,
"Body": self.body,
"Cabin Type": self.cab_type,
"Truck Bed": self.bed,
"Exterior Condition": self.e_condition,
"Interior Condition": self.i_condition,
"Drive Type": self.drive_type,
"Dealer Licence": self.dealer_licence,
"Stock Number": self.stock_id,
"Liters": self.liters,
"Cylinders": self.cylinders,
"Fuel Type": self.fuel_type,
"Doors": self.doors,
"Belts": self.belts,
"Vin": self.vin,
"Title type": self.title,
"Exterior Color": self.exterior,
"Interior Color": self.interior
}