Skip to content

Instantly share code, notes, and snippets.

@RileyMShea
Created August 2, 2019 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RileyMShea/d75c9fa630833a42d7dad6373d3758e7 to your computer and use it in GitHub Desktop.
Save RileyMShea/d75c9fa630833a42d7dad6373d3758e7 to your computer and use it in GitHub Desktop.
Fixed spacing indents
import csv
import requests
from bs4 import BeautifulSoup
with open('dataoutput.csv', 'w+', encoding='utf-8', newline='') as f:
writer = csv.writer(f)
writer.writerow(['productname', 'Sallername', 'price', 'point', 'comment'])
toplamUrun = 0
for sayfaNo in range(1,2):
url = "https://www.n11.com/bilgisayar/yazici-tarayici-ve-aksesuarlari/toner?pg=" + str(sayfaNo)
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml")
urunler = soup.find_all("li", attrs={"class": "column"})
for row in urunler:
urunAdi = row.a.get("title")
urunLink = row.a.get("href")
print(urunAdi)
try:
urun_r = requests.get(urunLink)
toplamUrun += 1
except Exception:
print("Ürün Detayı Alınamadı.")
urun_soup = BeautifulSoup(urun_r.content, "lxml")
ozellikler = urun_soup.find_all("div", attrs={"class": "wrapper product"})
for row in ozellikler:
productname = row.find("div", attrs={"class":"nameHolder"}).find("h1").text[0:-1].strip()
Sallername = row.find("div", attrs={"class": "sallerTop"}).find("a").text.strip()
price = row.find("div", attrs={"class": "newPrice"}).find("ins").text[0:-3].strip()
point = row.find("span", attrs={"class": "point"}).text.strip()
comment = row.find("div", attrs={"class": "tab"}).find('span').text.strip()
print(Sallername + ' ' + price + ' ' + point + ' ' + comment)
writer.writerow([productname, Sallername, price, point, comment ])
print("Toplam {} Kadar Ürün Bulundu.".format(toplamUrun))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment