위키백과 문서를 XML 파일로 저장

Jmnote (토론 | 기여)님의 2024년 3월 25일 (월) 13:52 판 (새 문서: ==개요== ;위키백과 문서를 XML 파일로 저장 <syntaxhighlight lang='python' run> # API 요청을 보내어 데이터 가져오기 url = "https://en.wikipedia.org/w/api.php...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요

위키백과 문서를 XML 파일로 저장
# API 요청을 보내어 데이터 가져오기
url = "https://en.wikipedia.org/w/api.php"
params = {
    "action": "query",
    "format": "xml",
    "titles": "Albert_Einstein",
    "prop": "revisions",
    "rvprop": "content"
}
response = requests.get(url, params=params)
data = response.content

# XML 데이터를 파일로 저장
with open("wiki_data.xml", "wb") as file:
    file.write(data)
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}