Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2912

「英語→カタカナ変換機」を叩いて英単語をカタカナに変換したい

$
0
0
何? 英語→カタカナ変換機をBashかPythonで叩きたいなあと思った。 注意 連続して取得したい場合は十分なウェイトを空けておくこと。 Bash word="test" curl 'https://www.sljfaq.org/cgi/e2k_ja.cgi?o=json&word='"${word}"'&lang=ja' \ -A 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' { "words": [ { "j_pron_spell": "テスト", "type": "dictionary", "word": "test", "j_pron_only": "テスト" } ], "is_romaji": 0, "has_spelling": 0 } Python from json import loads from json import loads from pprint import pp from urllib.parse import urlencode from urllib.request import Request, urlopen url = "https://www.sljfaq.org/cgi/e2k_ja.cgi" data = { "o": "json", "word": "test", "lang": "ja", } headers = { "User-Agent": ( "Mozilla/5.0 (X11; Linux x86_64) " "AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/51.0.2704.103 Safari/537.36" ), } params = urlencode(data, doseq=True) req = Request(f"{url}?{params}", headers=headers) res = loads(urlopen(req).read()) pp(res) {'has_spelling': 0, 'words': [{'j_pron_spell': 'テスト', 'type': 'dictionary', 'word': 'test', 'j_pron_only': 'テスト'}], 'is_romaji': 0}

Viewing all articles
Browse latest Browse all 2912

Trending Articles