require 'open-uri'
require 'uri'
require 'json'
url = "https://ja.wikipedia.org/w/api.php?action=opensearch&format=json&search=#{URI.encode(keyword)}"
response = open(url)
response.charset
# =>
# "utf-8"
json = JSON.parse(response.read)
# =>
# [
# "植物",
# ["植物", "植物油", "植物園", "植物の進化", "植物油の一覧", "植物男子ベランダー", "植物園の一覧", "植物内生真菌", "植物図鑑 (小説)", "植物天然記念物一覧"],
# ["", "", "", "", "", "", "", "", "", ""],
# ["https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E6%B2%B9", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E5%9C%92", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E3%81%AE%E9%80%B2%E5%8C%96", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E6%B2%B9%E3%81%AE%E4%B8%80%E8%A6%A7", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E7%94%B7%E5%AD%90%E3%83%99%E3%83%A9%E3%83%B3%E3%83%80%E3%83%BC", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E5%9C%92%E3%81%AE%E4%B8%80%E8%A6%A7", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E5%86%85%E7%94%9F%E7%9C%9F%E8%8F%8C", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E5%9B%B3%E9%91%91_(%E5%B0%8F%E8%AA%AC)", "https://ja.wikipedia.org/wiki/%E6%A4%8D%E7%89%A9%E5%A4%A9%E7%84%B6%E8%A8%98%E5%BF%B5%E7%89%A9%E4%B8%80%E8%A6%A7"]
# ]
json[1].each do |s|
p s
end
# =>
# "植物"
# "植物油"
# "植物園"
# "植物の進化"
# "植物油の一覧"
# "植物男子ベランダー"
# "植物園の一覧"
# "植物内生真菌"
# "植物図鑑 (小説)"
# "植物天然記念物一覧"