-
Notifications
You must be signed in to change notification settings - Fork 4
/
code--headless.py
102 lines (98 loc) · 4.52 KB
/
code--headless.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
# -*- coding: utf-8 -*-
"""Untitled6.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Usxd6zfxQGfEF7trF5KZpfAqnAhpzrQO
"""
import pandas as pd
import numpy as np
import requests
from bs4 import BeautifulSoup
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium. common. exceptions import TimeoutException
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
listemm=[]
sy=1
while sy<50:
r=requests.get("https://www.trendyol.com/sr?wb=794&wc=103498&qt=cep+telefonu&st=cep+telefonu&attr=290%7C4183&pi=%22+str(sy)+%22%22")
soup=BeautifulSoup(r.content,"lxml")
bir=soup.find_all("div",attrs={"class ","p-card-chldrn-cntnr"})
time.sleep(0.01)
for st in bir:
link=("https://www.trendyol.com" + st.find_all('a')[0].get("href"))
browser=webdriver.Chrome("C:\Selenium\chromedriver",chrome_options=chrome_options)
browser.get(link)
try:
Marka=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/h1/a").text
except:
Marka="Markası Belirtilmemiş"
try:
Telefon_İsmi=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/h1/span").text
except:
Telefon_İsmiİsmi="İsim Belirtilmemiş"
try:
değerlendirme=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[1]/div[2]/div/a").text
except:
değerlendirme="Henüz Değerlendirilmemiş"
try:
kargo=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]").text
except:
kargo="KARGO YOK"
try:
indirim_oranı=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]").text
except:
indirim_oranı="İndirimsiz"
try:
indirimsiz_fiyat=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[1]/div[3]/div/div/span[1]").text
except:
indirimsiz_fiyat="NaN"
try:
Fiyat=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[1]/div[1]/div[1]/div[3]/div/div/span[2]").text
except:
Fiyat="Fiyatı Belirtilmemiş"
try:
Satıcı_Puanı=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[2]/div[2]/div[2]/div[2]/div/a/div").text
except:
Satıcı_Puanı="Puan Yok"
try:
Müşteri_Puanı=browser.find_element_by_xpath("//*[@id='product-detail-app']/div/div[7]/div[2]/div[1]/div/div[1]/span").text
except:
Müşteri_Puanı="Müşteri Puanı Yok"
try:
c=2
telefonn_özellikleri=[]
while c<90:
telefonun_özellikleri=browser.find_element_by_xpath("//*[@id='urun-ozellikleri']/div[2]/div["+str(c)+"]/div[2]").text
telefonn_özellikleri.append(telefonun_özellikleri)
c+=2
except:
pass
time.sleep(2)
try:
element = browser.find_element_by_css_selector('#product-detail-app > div > div.pr-rnr-w > div.pr-rnr-cn.gnr-cnt-br > div.pr-rnr-com-w > a')
browser.execute_script("arguments[0].click();", element)
except:
pass
try:
q=1
yorumlarr=[]
while q<60:
kullanıcı_yorumları=browser.find_element_by_xpath("//*[@id='rating-and-review-app']/div/div[2]/div/div[2]/div[3]/div[2]/div["+str(q)+"]/div[1]/div").text
kullanıcı_yorumlarım=kullanıcı_yorumları+"//"
yorumlarr.append(kullanıcı_yorumlarım)
q+=2
browser.quit()
except:
pass
listemm.append([link,Marka,Telefon_İsmi,değerlendirme,kargo,indirim_oranı,indirimsiz_fiyat,Fiyat,telefonn_özellikleri,Satıcı_Puanı,Müşteri_Puanı,yorumlarr])
sy+=1