Skip to content

Instantly share code, notes, and snippets.

@devig
Created May 23, 2019 23:18
Show Gist options
  • Save devig/d7b2633ab63dc395397293d3c2869e33 to your computer and use it in GitHub Desktop.
Save devig/d7b2633ab63dc395397293d3c2869e33 to your computer and use it in GitHub Desktop.
yml2csv
# -*- coding: UTF-8 -*-
import pandas as pd
from lxml import etree
import wget
import os
yml_df = pd.DataFrame()
#качаем выгрузку
try:
os.remove('finedesigngroup.xml')
wget.download('https://www.finedesigngroup.ru/bitrix/catalog_export/fine_f_yandex_vendor_export.php', 'finedesigngroup.xml')
except:
wget.download('https://www.finedesigngroup.ru/bitrix/catalog_export/fine_f_yandex_vendor_export.php', 'finedesigngroup.xml')
#парсим выгрузку
yml = etree.parse('finedesigngroup.xml').getroot()
#получаем списки имен товаров и ИД
name = yml.xpath('.//*/offer/name/text()')
id = yml.xpath('.//*/offer/@id')
#available = yml.xpath('.//*/offer/@available')
yml_df['name'] = name
yml_df['id'] = id
yml_df['url'] = yml.xpath('.//*/offer/url/text()')
yml_df['price'] = yml.xpath('.//*/offer/price/text()')
yml_df['vendor_code'] = yml.xpath('.//*/offer/vendorCode/text()')
yml_df['vendor'] = yml.xpath('.//*/offer/vendor/text()')
yml_df['category_id'] = yml.xpath('.//*/offer/categoryId/text()')
#количество товаров
#elements_quant = len(id)
#print(elements_quant)
yml_df.to_csv('finedesigngroup.csv', sep=';', encoding='utf-8')
@devig
Copy link
Author

devig commented May 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment