Skip to content

Commit edd7662

Browse files
author
Daniel
committed
test commit
0 parents  commit edd7662

File tree

8 files changed

+163
-0
lines changed

8 files changed

+163
-0
lines changed

myproject/project_files/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

myproject/project_files/bot.py

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
from project_files import link as url
2+
from selenium import webdriver
3+
from selenium.webdriver.common.by import By
4+
from selenium.webdriver.common.keys import Keys
5+
import os
6+
7+
8+
9+
10+
class Cars(webdriver.Chrome):
11+
def __init__(self, driver_path='D:\projekty\bot\chromedriver',
12+
teardown=False):
13+
self.driver_path = driver_path
14+
self.teardown = teardown
15+
super(Cars, self).__init__()
16+
self.implicitly_wait(15)
17+
self.maximize_window()
18+
19+
20+
def __exit__(self, exc_type, exc_val, exc_tb):
21+
if self.teardown:
22+
self.quit()
23+
24+
def land_first_page(self):
25+
self.get(url.URL)
26+
27+
def accept_button(self):
28+
accept = self.find_element(By.ID,
29+
'onetrust-accept-btn-handler'
30+
)
31+
accept.click()
32+
33+
def car_type(self, car=None):
34+
self.implicitly_wait(10)
35+
car_list = self.find_element(By.XPATH,
36+
'//input[@placeholder="Typ nadwozia"]'
37+
)
38+
car_list.send_keys(car)
39+
car_list.send_keys(Keys.ENTER)
40+
41+
def car_brand(self, brand=None):
42+
self.implicitly_wait(15)
43+
brand_list = self.find_element(By.XPATH,
44+
'//input[@placeholder="Marka pojazdu"]'
45+
)
46+
brand_list.send_keys(brand)
47+
brand_list.send_keys(Keys.ENTER)
48+
49+
def price(self, min_price, max_price):
50+
self.implicitly_wait(2)
51+
minimum = self.find_element(By.XPATH,
52+
'//input[@id="filter_float_price:from"]'
53+
)
54+
minimum.send_keys(min_price)
55+
minimum.send_keys(Keys.ENTER)
56+
57+
self.implicitly_wait(2)
58+
maximum = self.find_element(By.XPATH,
59+
'//input[@id="filter_float_price:to"]'
60+
)
61+
maximum.send_keys(max_price)
62+
maximum.send_keys(Keys.ENTER)
63+
64+
def years(self, min_year, max_year):
65+
self.implicitly_wait(2)
66+
minimum = self.find_element(By.XPATH,
67+
'//input[@id="filter_float_year:from"]'
68+
)
69+
minimum.send_keys(min_year)
70+
minimum.send_keys(Keys.ENTER)
71+
72+
self.implicitly_wait(2)
73+
maximum = self.find_element(By.XPATH,
74+
'//input[@id="filter_float_year:to"]'
75+
)
76+
maximum.send_keys(max_year)
77+
maximum.send_keys(Keys.ENTER)
78+
79+
def mileage(self, min_mileage, max_mileage):
80+
self.implicitly_wait(2)
81+
minimum = self.find_element(By.XPATH,
82+
'//input[@id="filter_float_mileage:from"]'
83+
)
84+
minimum.send_keys(min_mileage)
85+
minimum.send_keys(Keys.ENTER)
86+
87+
self.implicitly_wait(2)
88+
maximum = self.find_element(By.XPATH,
89+
'//input[@id="filter_float_mileage:to"]'
90+
)
91+
maximum.send_keys(max_mileage)
92+
maximum.send_keys(Keys.ENTER)
93+
94+
def search_all(self):
95+
self.implicitly_wait(10)
96+
button = self.find_element(By.CSS_SELECTOR,
97+
'[data-testid="submit-btn"]'
98+
)
99+
# second option
100+
button = self.find_element(By.XPATH,
101+
'//*[@data-testid="submit-btn"]'
102+
)
103+
self.implicitly_wait(10)
104+
button.click()
105+
106+
def city(self):
107+
self.implicitly_wait(30)
108+
elements = self.find_elements(By.XPATH,
109+
'//p[@class="e1b25f6f7 ooa-1otyv8u-Text eu5v0x0"]'
110+
)
111+
for element in elements:
112+
print( element.text)
113+
114+
115+
def info_car(self):
116+
self.implicitly_wait(30)
117+
elements = self.find_elements(by="xpath",
118+
value='//article[@class="ooa-1sz58zb e1b25f6f18"]'
119+
)
120+
for element in elements:
121+
title = element.find_element(by="xpath", value='./div/h2/a').text
122+
print(title)
123+
year = element.find_element(by="xpath", value="./div/div/ul/li[1]").text
124+
print(year)
125+
distance = element.find_element(by="xpath", value="./div/div/ul/li[2]").text
126+
print(distance)
127+
engine = element.find_element(by="xpath", value="./div/div/ul/li[3]").text
128+
print(engine)
129+
petrol = element.find_element(by="xpath", value="./div/div/ul/li[4]").text
130+
print(petrol)
131+
132+
133+
# def pages(self, page):
134+
# self.implicitly_wait(60)
135+
# self.page = page
136+
# # //*[name()='svg' and @class="ooa-1xwoou1"]
137+
# # next_page = self.find_element(By.PARTIAL_LINK_TEXT,
138+
# # f'{self.page}'
139+
# # )
140+
# next_page = self.find_element(By.XPATH,
141+
# '//*[name()="svg" and @class="ooa-1xwoou1"]'
142+
# )
143+
# next_page.click()
144+
# print('loooool')

myproject/project_files/link.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
URL = "https://www.otomoto.pl/"

myproject/run.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from project_files.bot import Cars
2+
3+
try:
4+
with Cars() as bot:
5+
bot.land_first_page()
6+
bot.accept_button()
7+
#bot.car_type(car='Auta małe')
8+
bot.car_brand(brand='Renault')
9+
bot.price(min_price='0', max_price='15000')
10+
bot.years(min_year='2000', max_year='2010')
11+
bot.mileage(min_mileage='0', max_mileage='2000000')
12+
bot.search_all()
13+
# bot.city()
14+
# bot.info_car()
15+
# bot.pages(page=2)
16+
17+
except:
18+
'There is a problem with a main bot'

0 commit comments

Comments
 (0)