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

Jmnote (토론 | 기여)님의 2024년 3월 25일 (월) 14:11 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

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

2 예시 1[ | ]

import requests

# 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
print(data)

# XML 데이터를 파일로 저장
with open("wiki_data.xml", "wb") as file:
    file.write(data)

3 예시 2[ | ]

import requests

url = "https://en.wikipedia.org/w/api.php"
params = {
    "action": "query",
    "export": 1,
    "format": "xml",
    "titles": "Albert_Einstein"
}
response = requests.get(url=url, params=params)
data = response.text
print(data)

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}