Feb-26-2019, 01:58 PM
(This post was last modified: Feb-26-2019, 01:58 PM by erdem_ustunmu.)
hi snippsat;
I tried to get and combine the categories according to the code you wrote yesterday.
When I tried to do it yesterday, it brought the latest category, not all categories.
Now I've tried to make it look like you wrote it, but it didn't.
I wonder if I'm making a logical mistake.
so far codes:
I tried to get and combine the categories according to the code you wrote yesterday.
for cat in var.find_all('catgry'): cat_value=[value.text.strip() for value in cat.find_all('catValu')] cat_label=[value.text.strip() for value in cat.find_all('labl')] cat_stat=[value.text.strip() for value in cat.find_all('catStat')] categories=dict(list(zip(cat_value, cat_label,cat_stat))) print(categories)
When I tried to do it yesterday, it brought the latest category, not all categories.
Now I've tried to make it look like you wrote it, but it didn't.
I wonder if I'm making a logical mistake.
so far codes:
from bs4 import BeautifulSoup lst = [] categories = [] soup = BeautifulSoup(open('NPL_2008_LFS_v01_M_v01_A_ILOVAR.xml', encoding='utf-8'), 'xml') title = soup.find('titl') producer = soup.find('producer') data = soup.find('dataDscr') vars = data.find_all('var') for var in vars: ID=var.attrs.get('ID') name=var.attrs.get('name') files=var.attrs.get('files') dcml=var.attrs.get('dcml') intrvl=var.attrs.get('intrvl') labl=var.find('labl').text.strip() sum_Stat=[i.text.strip() for i in var.find_all('sumStat')] sum_Att = [i.attrs['type'] for i in var.find_all('sumStat')] sumStat=dict(list(zip(sum_Att, sum_Stat))) VarFormat=(var.find('varFormat')).attrs.get('type') stdCatgry = [stdCat.text.strip() for stdCat in var.find_all("stdCatgry")] Range = [i.attrs for i in var.find_all('range')] for cat in var.find_all('catgry'): cat_value=[value.text.strip() for value in cat.find_all('catValu')] cat_label=[value.text.strip() for value in cat.find_all('labl')] cat_stat=[value.text.strip() for value in cat.find_all('catStat')] categories=dict(list(zip(cat_value, cat_label,cat_stat))) print(categories) print(title.text.strip(),producer.text.strip(),ID,name,files,dcml,intrvl,labl,sumStat,VarFormat,stdCatgry,Range,categories) lst.append((title.text.strip(),producer.text.strip(),ID,name,files,dcml,intrvl,labl,sumStat,VarFormat,stdCatgry,Range,categories))