Skip to content

Instantly share code, notes, and snippets.

@RileyMShea
Created August 2, 2019 10:01
Show Gist options
  • Select an option

  • Save RileyMShea/d75c9fa630833a42d7dad6373d3758e7 to your computer and use it in GitHub Desktop.

Select an option

Save RileyMShea/d75c9fa630833a42d7dad6373d3758e7 to your computer and use it in GitHub Desktop.

Revisions

  1. RileyMShea created this gist Aug 2, 2019.
    38 changes: 38 additions & 0 deletions nll_scrape.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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))