0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

とりあえずたくさんの単語が欲しいときのプログラム

Last updated at Posted at 2021-10-09

注意

オートコンプリートのAPIポリシー等を検索していみましたが、こういう使い方がいけないみたいな記述はみつけられませんでした、、が実行は自己責任でお願いします。
※正直自分が見つけられないだけかもしれません。

こんな感じのもの

テストデータなんかを作るときに、とりあえず全角の単語が欲しい時に使用
コンソール上に単語がたくさん出ます(440くらい)
こちらの方のプログラムを半分以上流用していますm(_ _)m

環境

windows10
python3.9.4

pip実行(以下パッケージが必要)

python -m pip install requests
python -m pip install lxml
python -m pip install numpy
python -m pip install pandas

ソース

test.py
import pprint
import requests
from lxml import etree
import numpy as np
import pandas as pd

qstrs = ["", "", "", "", "", "", "", "", "", "",
         "", "", "", "", "", "", "", "", "", "",
         "", "", "", "", "", "", "", "", "", "",
         "", "", "", "", "", "", "", "",
         "", "", "", "", "", "" ]

# 単語格納用
google_suglist = []

# ひらがな分ループ
for qstr in qstrs:

    # オートコンプリートのデータを取得する
    google_r = requests.get("https://www.google.com/complete/search",
                    params={'q':qstr,
                            'hl':'ja',
                            'ie':'utf_8',
                            'oe':'utf_8',
                            'output': 'toolbar'})

    google_root = etree.XML(google_r.text)

    google_sugs = google_root.xpath("//suggestion")
    google_sugstrs = [s.get("data") for s in google_sugs]

    for ss in google_sugstrs:
        google_suglist.append(ss)
        # print(ss)

# コンソール出力
for word in google_suglist:
    print(word)

実行(要らんでしょうが…)

python test.py

最後に

ランダムで1文字生成してとかにすると、もうちょっと良いものになるかも、、

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?