In [1]:
d00_data= open('00_data.text', 'w',encoding='utf8')
d00_data.write('hi')
d00_data.write('hwi')
d00_data.write('hiw')
d00_data.close()
In [2]:
import requests
from bs4 import BeautifulSoup
keyword = '카타르월드컵'
google_related_keyword_api = 'http://suggestqueries.google.com/complete/search?output=toolbar&q=' + keyword
response = requests.get(google_related_keyword_api) # 파일이 아니라, 데이터를 Open API 에서 가져오기 위한 함수
soup = BeautifulSoup(response.content, 'xml') # requests.get() 의 리턴값은 객체
# 객체.content 에 가져온 데이터가 있음
datas1 = soup.select('suggestion')
for item in datas1:
print(item['data'])
카타르월드컵
카타르월드컵 조추첨
카타르월드컵 유니폼
카타르월드컵 조편성
카타르월드컵 공인구
카타르월드컵 조
카타르월드컵 대한민국 유니폼
카타르월드컵 티켓
카타르월드컵 최종예선
카타르월드컵 대진표
In [3]:
import json
data= { "id":"01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }
data['lan']=['java','python']
with open('test.json', 'w',encoding='utf-8-sig') as json_file:
json_string=json.dump(data, json_file, indent=2)
In [4]:
import json
# 변수에 문자열로 된 JSON 포멧의 데이터가 있을 경우
data = { "id":"01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }
data['language'] = ['Java', 'C']
with open('test1.json', 'w', encoding='utf-8-sig') as json_file:
json_string = json.dump(data, json_file, indent=2)
In [ ]:
'파이썬 활용 > 다양한 파일들 불러는 방법' 카테고리의 다른 글
xml 불러오기 (0) | 2022.10.24 |
---|