def get_data(context): html = get_html( 'https://www.colins.com.tr/urun/893-julia-normal-kesim-orta-bel-kisa-paca-mavi-jean-pantolon-16434' ) data = {} soup = BeautifulSoup(html, 'lxml') base = soup.find('div', id='page').find( 'div', class_='fullContent top-space').find('div').find('div').find( 'div').find( 'div', class_='row product-details-page').find('div').find('form') images_soup = base.find( 'div', class_='productDetailLeftPanel col-lg-6 col-sm-6' ).find('div').find('div').find( 'div', class_='module-frameproduct-picture-wrapper').find('div').find_all('a') description = '' try: tr = (soup.find('div', id='page').find( 'div', class_='fullContent top-space').find('div').find( 'div').find('div').find( 'div', class_='product-details-mobile row').find('div').find( 'div', class_='PDTABSCONTENT clearfix tab-content').find( 'div', class_='tab-pane active').find( 'table').find('tbody').find_all('tr')[1]) description = tr.find('td').text.strip() except: pass images = [] for i in images_soup: images.append(i['data-image']) right = base.find('div', class_='productDetailRightPanel') name_soup = right.find('h1') name = name_soup.text.strip() others = right.find('div', class_='product-collateral').find('div').find( 'div', class_='variant-wrapper').find('div') color = others['data-variant-name'].lower().capitalize() price = others.find('div', class_='productPriceContent clearfix').find( 'span').text.strip().split(' ')[0].replace(',', '.') variants = others.find( 'div', class_='product-options').find('div').find_all('div') sizes = [] for i in variants: classes = i['class'] size = {'value': i.find('label').text.strip()} if len(classes) == 2: size['stock'] = False else: size['stock'] = True sizes.append(size) print(sizes) return []
def main(): url = 'https://magicbox.izishop.kg/api/v1/project/brands/?brand=bershka' # url = 'http://127.0.0.1:8000/api/v1/project/brands/zara/' request_url = 'https://www.bershka.com/itxrest/2/catalog/store/44109521/40259537/category?languageId=-43&typeCatalog=1&appId=2' html = get_html(request_url) massimo = json.loads(html) categories = [massimo['categories'][0], massimo['categories'][3]] departments = [] for i in categories: department = { 'department': i['name'], 'link': 'https://www.bershka.com/tr/', } collection = None for j in i['subcategories']: if j['name'] == 'KOLEKSİYON': collection = j break sub_categories = [] for category in collection['subcategories']: if len(category['subcategories'] ) == 0 and category['viewCategoryId'] > 0: n_category = { 'category': category['name'], 'link': 'https://www.bershka.com/tr/%s/koleksi̇yon/%s-c%s.html' % (str(i['name']).lower(), str(category['name']).replace( ' ', '-').lower(), category['id']) } sub_categories.append(n_category) elif len(category['subcategories']) > 0: for sub in category['subcategories'][1:]: n_category = { 'category': '%s (%s)' % (category['name'], sub['name']), 'link': 'https://www.bershka.com/tr/%s/koleksi̇yon/%s/%s-c%s.html' % (str(i['name']).lower(), str(category['name']).replace( ' ', '-').lower(), str(sub['name']).replace( ' ', '-').lower(), sub['id']) } sub_categories.append(n_category) department['categories'] = sub_categories departments.append(department) pprint(departments) headers = { 'Content-type': 'application/json', 'Accept': 'application/json' } r = requests.put(url, data=json.dumps(departments), headers=headers) print(r.status_code) departments = []
def main(): url = 'https://magicbox.izishop.kg/api/v1/project/brands/?brand=stradivarius' # url = 'http://127.0.0.1:8000/api/v1/project/brands/?brand=stradivarius' request_url = 'https://www.stradivarius.com/itxrest/2/catalog/store/54009571/50331081/category?languageId=-43&typeCatalog=1&appId=2' html = get_html(request_url) stradivarius = json.loads(html) categories = stradivarius['categories'][0]['subcategories'] new_categories = [categories[1], categories[3]] departments = [] department = { 'department': 'Kadin', 'link': 'https://www.stradivarius.com/tr/', } sub_categories = [] for i in new_categories: parent = i['subcategories'][0] for category in parent['subcategories'][1:]: if len(category['subcategories']) == 0: print(category['name']) n_category = { 'category': category['name'], 'link': 'https://www.stradivarius.com/tr/yeni-koleksiyon/%s/ürüne-göre-alışveriş/%s-c%s.html' % (str(i['name']).lower(), str(category['name']).replace( ' ', '-').lower(), category['id']) } sub_categories.append(n_category) elif len(category['subcategories']) > 0: for sub in category['subcategories'][1:]: n_category = { 'category': '%s (%s)' % (category['name'], sub['name']), 'link': 'https://www.stradivarius.com/tr/yeni-koleksi̇yon/%s/ürüne-göre-alışveriş/%s/%s-c%s.html' % (str(i['name']).lower(), str(category['name']).replace( ' ', '-').lower(), str(sub['name']).replace( ' ', '-').lower(), sub['id']) } sub_categories.append(n_category) department['categories'] = sub_categories departments.append(department) pprint(departments) headers = { 'Content-type': 'application/json', 'Accept': 'application/json' } r = requests.put(url, data=json.dumps(departments), headers=headers) print(r.status_code)
def parse_brand_data(brand): data = [ { 'name': 'Kadın', 'link': 'https://www2.hm.com/tr_tr/kadin.html' }, { 'name': 'Erkek', 'link': 'https://www2.hm.com/tr_tr/erkek.html' }, { 'name': 'Divided', 'link': 'https://www2.hm.com/tr_tr/divided.html' }, { 'name': 'Çocuk', 'link': 'https://www2.hm.com/tr_tr/cocuk.html' }, ] l = [] for i in data: context = {'department': i['name'], 'link': i['link']} html = get_html(context['link']) soup = BeautifulSoup(html, 'lxml') menu = soup.find('div', class_='sidebar-plus-content').find('aside', class_='page-sidebar').find('nav', class_='secondary-nav') \ .find('ul', id='menu-links').find_all('li', class_='list-group') all_categories = [] for i in menu: menu_item = None try: menu_item = i.find('strong', class_='list-group-title is-opened') except: pass if menu_item is not None: ul = i.find('ul', class_='menu').find_all('li') for j in ul: category = {} a = j.find('a') if a['href'] != '/tr_tr/kadin/urune-gore-satin-al/view-all.html' \ or a['href'] != '/tr_tr/erkek/urune-gore-satin-al/view-all.html'\ or a['href'] != '/tr_tr/cocuk/urune-gore-satin-al/view-all.html': category['link'] = 'https://www2.hm.com' + a['href'] category['name'] = a.text.strip() all_categories.append(category) context['categories'] = all_categories l.append(context) return l
def get_data(): html = get_html( 'https://www2.hm.com/tr_tr/erkek/urune-gore-satin-al/ayakkabi.html') soup = BeautifulSoup(html, 'lxml') menu = soup.find('div', class_='sidebar-plus-content').find('aside').find('nav', class_='secondary-nav') \ .find('ul', id='menu-links').find_all('li', class_='list-group') for i in menu: menu_item = None try: menu_item = i.find('strong', class_='list-group-title is-opened') except: pass if menu_item is not None: ul = (i.find('ul', class_='menu').find( 'li', class_='list-group').find('ul').find_all('li')) categories = [{ 'category': j.find('a').text.strip(), 'link': 'https://www2.hm.com' + j.find('a')['href'] } for j in ul] print(categories) return []
def parse_brand_data(brand): data = [ { 'name': 'Kadın', 'link': 'https://www.colins.com.tr/c/kadin-giyim-57' }, { 'name': 'Erkek', 'link': 'https://www.colins.com.tr/c/erkek-giyim-2' }, { 'name': 'Aksesuar', 'link': 'https://www.colins.com.tr/c/aksesuar-465' }, ] l = [] for i in data: context = {'department': i['name'], 'link': i['link']} html = get_html(context['link']) soup = BeautifulSoup(html, 'lxml') menu = soup.find('div', id='page').find('div', class_='fullContent top-space').find('div', class_='container catalog-category') \ .find('div', class_='productFilterContent').find('div', class_='panel-heading clearfix group-container-Kategori') \ .find('div').find('div').find('ul').find_all('li') pprint(menu) categories = [] for i in menu: category = { 'category': i.find('a').text.strip(), 'link': i.find('a')['href'], } categories.append(category) context['categories'] = categories l.append(context) return l
def parse_brand_data(brand): url = brand['link'] html = get_html(url) soup = BeautifulSoup(html, 'lxml') data = soup.find('div', id='nav-menu-group').find('nav', id='menu').find('ul', class_='category-menu') \ .find_all('li', class_='_category-link-wrapper menu-item menu-item--level-1') data = data[1:5] l = [] for i in data: context = { 'department': i['data-name'], 'link': i.find('a', class_='_category-link menu-item__category-link')['href'] } html = get_html(context['link']) soup = BeautifulSoup(html, 'lxml') departments = soup.find('div', id='nav-menu-group').find('nav', id='menu').find('ul', class_='category-menu') \ .find('li', class_='_category-link-wrapper menu-item menu-item--level-1 menu-item--current menu-item--selected') ul = departments.find( 'ul', class_= '_subcategories subcategory-menu subcategory-menu--level-1 subcategory-menu--current' ) classes = (ul.find_all( 'li', class_='_category-link-wrapper menu-item menu-item--level-2')) categories = [] for classi in classes: name = classi['data-name'] cats = classi.find('ul', class_='_subcategories subcategory-menu subcategory-menu--level-2') \ .find_all('li', class_='_category-link-wrapper menu-item menu-item--level-3 menu-item--is-leaf') cats = cats[1:] for category in cats: category_data = { 'category': '%s (%s)' % (category['data-name'], name) } try: link = category.find( 'a', class_='_category-link menu-item__category-link' )['href'] except: link = category.find( 'a', class_='_category-link menu-item__category-link' )['data-href'] category_data['link'] = link categories.append(category_data) leafs = (ul.find_all( 'li', class_= '_category-link-wrapper menu-item menu-item--level-2 menu-item--is-leaf' )) for leaf in leafs: class_data = {'category': leaf['data-name']} try: link = leaf.find( 'a', class_='_category-link menu-item__category-link')['href'] except: link = leaf.find( 'a', class_='_category-link menu-item__category-link' )['data-href'] class_data['link'] = link categories.append(class_data) context['categories'] = categories l.append(context) return l