Created
May 23, 2019 23:18
-
-
Save devig/d7b2633ab63dc395397293d3c2869e33 to your computer and use it in GitHub Desktop.
yml2csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/beevik/etree