Bu bir deneme çalışması ama belkide işinize yarar. Sarı web sayfasındaki sonuçların fiyatlarını alıp lineer reg ile fiyat analizi yapıyor. Sorguyu zaman sıralaması yaparak kullanırsanız daha anlamlı veriler elde edersiniz. Fiyatlar düşüyor mu yoksa çıkıyor mu?
chromedriver i https://chromedriver.chromium.org/getting-started dan indirebilirsiniz.
–düzenleme–
01.11.2022 tarihinde kodlar düzenlenmiştir.
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 |
# -*- coding: utf-8 -*- from selenium.webdriver.common.by import By from tqdm import tqdm from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.chrome.options import Options import matplotlib.pyplot as plt import numpy as np import pandas as pd import os ''' chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome(executable_path='chromedriver',options=chrome_options)#chromedriver ın yolu yazılır ''' from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #driver.get("https://www.google.com") url="https://www.sahibinden.com/motosiklet-honda-nc-750-x-dct?sorting=date_asc" driver.get(url) driver.wait = WebDriverWait(driver, 5) try: sayfaSayisi=driver.find_element(by=By.CLASS_NAME,value="mbdef") sayfaSayisiVal=sayfaSayisi.text sayfaSayisiVal=int(sayfaSayisiVal.split()[1]) print(sayfaSayisiVal) except IndexError: sayfaSayisiVal=1 fiyatlar=[] tarihler=[] paging = "&pagingOffset=" ''' print( url.find('?')) if url.find('?')==1: paging = "?pagingOffset=" else: paging = "&pagingOffset=" ''' try: for sayfa in tqdm(range(sayfaSayisiVal)): if sayfa==0: nurl=url else: nurl=url+(paging+str(sayfa*20)) driver.get(nurl) driver.wait = WebDriverWait(driver, 10) araclar = driver.find_elements(by=By.CLASS_NAME,value="searchResultsItem") #aracFiyatlari = araclar.find_elements(by=By.CLASS_NAME, value="searchResultsItem") for i in araclar: try: fiyat=i.find_element(by=By.CLASS_NAME,value="searchResultsPriceValue") fiyatlar.append(float(fiyat.text.split()[0])) except: pass #fiyatlar.append(float(fiyat[1][0].text.split()[0])) except: pass driver.wait = WebDriverWait(driver, 5) driver.close() x=np.arange(0,len(fiyatlar)) A = np.vstack([x, np.ones(len(x))]).T m, c = np.linalg.lstsq(A, fiyatlar, rcond=None)[0] plt.plot(x, m*x + c, 'r', label='Fitted line') plt.scatter(x=x,y=fiyatlar) plt.xticks() print(x.max()) plt.title(url+"\nToplam:"+str(fiyatlar.__len__())) plt.show() #driver.save_screenshot("test.png") |
Ziyaretci : 2198