En Ucuz Ürün arama

Merhaba ;
ufak bir program ama birilerinin ihtiyacı olabilir diye yüklüyorum

# -*- coding: utf-8 -*-
from tkinter import *
from tkinter import scrolledtext
import requests
from parsel import Selector
import re

penc =Tk()
penc.title("Ürün Arama")
penc.geometry("450x500")

uygulama=Frame(penc)
uygulama.grid()

L1 = Label(uygulama, text="Aranılacak Ürün : ")
L1.grid(row=1,column=0)

E1 = Entry(uygulama, bd=2,width="30")
E1.grid(row=2,column=0)


def islemler(): # bütün aramaların yazdırması konsolda işliyor
    trend()
    n11()
    hepsi()
    gitti()

textt=Text(master=uygulama,height=150, width=50)
textt.grid(row=4,column=0)

def trend(): #trendyol arama
        ara=str(E1.get())
        ara.replace(" ","%20")
        birles="https://www.trendyol.com/tum--urunler?q={}&siralama=1&qt={}&st={}".format(ara,ara,ara)
        target_url=birles

        headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
        }

        response = requests.get(target_url, headers=headers)


        if response.status_code == 200:

            textt.insert(INSERT,"\n**********************\n" )
            print(" ")
            selector = Selector(response.text)
            REGEX = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
            isim = selector.css('div > div.srch-rslt-cntnt > div.srch-prdcts-cntnr > div:nth-child(2) > div > div:nth-child(1) > a > div.prdct-desc-cntnr-wrppr > div.prdct-desc-cntnr > div > span.prdct-desc-cntnr-name').get()
           # magaza = selector.selectorlist_cls('/html/body/div[4]/div[2]/div/div[2]/div[4]/div[2]/ul/li[1]/a/div/div/div[2]/div/span[2]/span').get()
            price = selector.css('#search-app > div > div.srch-rslt-cntnt > div.srch-prdcts-cntnr > div:nth-child(2) > div > div:nth-child(1) > a > div.prdct-desc-cntnr-wrppr > div.prc-cntnr > div.prc-box-sllng').get()

            trendurunadi=REGEX.sub('', isim).strip()
            trendurunfiyat=REGEX.sub('', price).strip()

            textt.insert(INSERT,'\nTrendyol ÜRÜN DETAYLARI:')
            textt.insert(INSERT,"'\nÜrün Adı: {}".format(trendurunadi))
               # print('Mağaza: ', REGEX.sub('', magaza).strip())
            textt.insert(INSERT,'\nFiyatı: {}'.format(trendurunfiyat) )

        else:
            print('trendyol Bağlantı kurulamadı! HTTP Kodu: ', response.status_code)


def gitti(): #gittigidiyor arama
        ara=str(E1.get())

        ara.replace(" ","%20")

        birles = "https://www.gittigidiyor.com/arama/?k={}&sra=hpa".format(ara)
        target_url = birles

        headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
        }

        response = requests.get(target_url, headers=headers)


        if response.status_code == 200:

            textt.insert(INSERT, "\n**********************\n")
            print(" ")
            selector = Selector(response.text)
            REGEX = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
            isim = selector.xpath(
                '/html/body/div[4]/div[2]/div/div[2]/div[4]/div[2]/ul/li[1]/a/div/div/div[1]/div[1]/h3/span').get()
            magaza = selector.xpath(
                '/html/body/div[4]/div[2]/div/div[2]/div[4]/div[2]/ul/li[1]/a/div/div/div[2]/div/span[2]/span').get()
            price = selector.xpath(
                '/html/body/div[4]/div[2]/div/div[2]/div[4]/div[2]/ul/li[1]/a/div/div/div[1]/div[2]/div/div[1]/div/div/div[4]/p').get()

            gittiurun=REGEX.sub('', isim).strip()
            gittimagaza=REGEX.sub('', magaza).strip()
            gittifiyat=REGEX.sub('', price).strip()


            textt.insert(INSERT,'\nGittiGidiyor ÜRÜN DETAYLARI:')
            textt.insert(INSERT,'\nÜrün Adı: {} '.format(gittiurun))
            textt.insert(INSERT,'\nMağaza: {}'.format(gittimagaza) )
            textt.insert(INSERT,'\nFiyatı: {} ' .format(gittifiyat))


        else:
            print('GittiGidiyor Bağlantı kurulamadı! HTTP Kodu: ', response.status_code)


def n11(): #n11 arama
        ara=str(E1.get())

        ara.replace(" ","+")

        birles = "https://www.n11.com/arama?q={}&srt=PRICE_LOW".format(ara)
        target_url = birles

        headers = {
            'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
        }

        response = requests.get(target_url, headers=headers)


        if response.status_code == 200:

            textt.insert(INSERT,"\n**********************\n" )
            print(" ")
            selector = Selector(response.text)
            REGEX = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
            isim = selector.xpath('/html/body/div[1]/div[2]/div/div/div[2]/section/div[2]/ul/li[1]/div/div[1]/a/h3').get()
            magaza = selector.xpath('/html/body/div[1]/div[2]/div/div/div[2]/section/div[2]/ul/li[1]/div/a/span[2]').get()
            price = selector.xpath('/html/body/div[1]/div[2]/div/div/div[2]/section/div[2]/ul/li[1]/div/div[2]/a[2]/ins/text()').get()

            n11urun = REGEX.sub('', isim).strip()
            n11magaza = REGEX.sub('', magaza).strip()
            n11fiyat = REGEX.sub('', price).strip()

            textt.insert(INSERT,'\nN11 ÜRÜN DETAYLARI:')
            textt.insert(INSERT,'\nÜrün Adı: {}'.format(n11urun) )
            textt.insert(INSERT,'\nMağaza: {}'.format(n11magaza) )
            textt.insert(INSERT,'\nFiyatı: {} '.format(n11fiyat))


        else:
            print('N11 Bağlantı kurulamadı! HTTP Kodu: ', response.status_code)


def hepsi(): # hepsiburada aram
        ara=str(E1.get())

        ara.replace(" ","+")

        birles = "https://www.hepsiburada.com/ara?q={}&siralama=artanfiyat".format(ara)
        target_url = birles

        headers = {
            'User-Agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
        }

        response = requests.get(target_url, headers=headers)


        if response.status_code == 200:

            textt.insert(INSERT,"\n**********************\n\n" )
            print(" ")
            selector = Selector(response.text)
            REGEX = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
            isim = selector.xpath(
                '/html/body/div[3]/main/div[2]/div/div/div/div/div[2]/section/div[1]/div[3]/div/div/div/div/ul/li[1]/div/a/div/h3/div/p/span').get()
            # magaza = selector.xpath('//*/a/span[2]').get()
            price = selector.xpath(
                '/html/body/div[3]/main/div[2]/div/div/div/div/div[2]/section/div[1]/div[3]/div/div/div/div/ul/li[1]/div/a/div/div[2]/span').get()

            hepsiurun=REGEX.sub('', isim).strip()
            hepsifiyat=REGEX.sub('', price).strip()


            textt.insert(INSERT,'HepsiBurada ÜRÜN DETAYLARI:')
            textt.insert(INSERT,'\nÜrün Adı: {}'.format(hepsiurun) )
            # print('Mağaza: ', REGEX.sub('', magaza).strip())
            textt.insert(INSERT,'\nFiyatı: {} '.format(hepsifiyat) )

        else:
            print('HepsiBurada Bağlantı kurulamadı! HTTP Kodu: ', response.status_code)


def sil():
    textt.delete(1.0,END)

arama=Button(uygulama,text='Ara',width=5,height=1,command=islemler)
arama.grid(row=1,column=1)

silme=Button(uygulama,text='Temizle',width=5,height=1,command=sil)
silme.grid(row=2,column=1)

penc.mainloop()

@dildeolupbiten ve @EkremDincel e yardımları için Teşekkürler

3 Beğeni