Example #1
0
soup = BeautifulSoup(xml, 'html.parser')
for node in soup.findAll('node'):
    print("Node : " + node.string)
    print("Attr1 : " + node['attr1'])

f = open('song.xml', encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml, 'html.parser')
for nodes in soup.test('song'):
    for node in nodes:
        print(node.string)

f = open('alcohol.xml', encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml, 'html.parser')
for nodes in soup.alcohol('cate1'):
    print('Cate1 :' + nodes['tt'])
    for node in nodes('cate2'):
        print('\tCate2 :' + node['tt'])
        for item in node('item'):
            print('\t\t' + item.string)

#안주만 받아오세요
f = open('alcohol.xml', encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml, 'html.parser')
for nodes in soup.alcohol('cate1'):
    if nodes['tt'] == "안주":
        print('Cate1 :' + nodes['tt'])
        for node in nodes('cate2'):
            print('\tCate2 :' + node['tt'])
Example #2
0
    except:
        print()

#Song xml 예제
f=open('song.xml',encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml)
for nodes in soup.test('song'):
    for node in nodes:
        print(node.string)

#Alcohol xml 예제
f=open('alcohol.xml',encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml,'lxml')
for nodes in soup.alcohol('cate1'):
    if nodes['tt']=="안주":
        print('Cate1:'+nodes['tt'])
        for node in nodes('cate2'):
            print('\tCate2:'+node['tt'])
            for item in node('item'):
                print('\t\t'+item.string)

#Jason 파싱 예제
import json
data={1:'a',2:'b'}
data2=json.dumps(data)
data3=json.loads(data2)
print(data2)
print(type(data2))
print(data3.keys())
Example #3
0
#파일 오픈할때 솔루션 탐색기에서 추가 기존항목으로 xml파일 만들기!

f = open('song.xml', encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml)
for nodes in soup.test('song'):
    for node in nodes:
        print(node.string)


import re

f = open('alcohol.xml', encoding='utf-8')
xml = f.read()
soup = BeautifulSoup(xml,'html.parser')
if soup.alcohol('cate1') == "안주": 
 for nodes in soup.alcohol('cate1'):
    print('Cate 1:' + nodes['tt'])
    for node in nodes('cate2'):
        print('\tCate2 :' + node['tt'])
        for item in node('item'):
            print('\t\t' + item.string)


#카테고리중에서 안주에 해당하는것만 출력해보기


#과제가 있다 open api를 설정하여 그룹과제
# 반드시 github를 만들어서 공유할수 있도록 하라
# 이력이 남도록 해야 된다 / 주소는 교수님께 보낼수 있도록하라
#내가 원하는 데이터의 형태를 뽑아 내야된다....