"위키백과 문서를 XML 파일로 저장"의 두 판 사이의 차이

(새 문서: ==개요== ;위키백과 문서를 XML 파일로 저장 <syntaxhighlight lang='python' run> # API 요청을 보내어 데이터 가져오기 url = "https://en.wikipedia.org/w/api.php...)
 
3번째 줄: 3번째 줄:


<syntaxhighlight lang='python' run>
<syntaxhighlight lang='python' run>
import requests
# API 요청을 보내어 데이터 가져오기
# API 요청을 보내어 데이터 가져오기
url = "https://en.wikipedia.org/w/api.php"
url = "https://en.wikipedia.org/w/api.php"

2024년 3월 25일 (월) 13:53 판

개요

위키백과 문서를 XML 파일로 저장
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

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