Question
20 Read JSON data
Read the JSON file of the Wikipedia article and display the article text about "UK". In problems 21-29, execute on the article text extracted here.
Answer
import json
with open("jawiki-country.json") as f:
for line in f:
line_data = json.loads(line)
if line_data["title"] == "England":
data = line_data
break
print(data["text"][:1000])
# {{redirect|UK}}
# {{redirect|United Kingdom|The princes of the Spring and Autumn period|English(Spring and autumn)}}
# {{Otheruses|European country|Local cuisine of Nagasaki and Kumamoto prefectures|England}}
# {{Basic information Country
# |Abbreviated name=England
# |Japanese country name=United Kingdom of Great Britain and Northern Ireland
# |Official country name= {{lang|en|United Kingdom of Great Britain and Northern Ireland}}<ref>Official country name other than English:<br />
# *{{lang|gd|An Rìoghachd Aonaichte na Breatainn Mhòr agus Eirinn mu Thuath}}([[Scottish Gaelic]])
# *{{lang|cy|Teyrnas Gyfunol Prydain Fawr a Gogledd Iwerddon}}([[Welsh]])
# *{{lang|ga|Ríocht Aontaithe na Breataine Móire agus Tuaisceart na hÉireann}}([[Irish]])
# *{{lang|kw|An Rywvaneth Unys a Vreten Veur hag Iwerdhon Glédh}}([[Cornish]])
# *{{lang|sco|Unitit Kinrick o Great Breetain an Northren Ireland}}([[Scots]])
# **{{lang|sco|Claught Kängrick o Docht Brätain an Norlin Airlann}}、{{lang|sco|Unitet Kängdom o Great Brittain an Norlin Airlann}}(Ulster Scots)</ref>
# |National flag image= Flag of the United Kingdom.svg
# |National emblem image= [[File:Royal Coat of Arms of the United Kingdom.svg|85px|British coat of arms]]
# |National emblem link=([[British coat of arms|National emblem]])
with open("uk_text.txt", "w") as f:
f.write(data["text"])
Recommended Posts