Ankiデッキ作成のため、自動で単語から例文を取得する(python,webスクレイピング)

英語学習のため、Ankiというアプリを使っている。
そのアプリではcsvのデータを取り込むことが可能で、アドオン(AwsomeTTS)を使えば自動で音声をつけることもできる

 

今回は、インターネットで収集した単語データに、例文がほしいなと思ったのでweblio辞書から例文を取得するプログラムを書いた。webスクレイピング便利

 

もともと[英単語,和訳]というデータに対して
三行目に例文を3つ追加する感じにしてみた。

 

data = pd.read_excel("eiken1.xlsx")
data.head(5) #元のデータ
 
 
example_list = ["-" for a in range(3149)]

for i in range(3149):
    print(data.iloc[i][0], data.iloc[i][1], end = " : ")
    word = data.iloc[i][0]


    try:
        res = requests.get(url +"/" + word)
        soup = BeautifulSoup(res.content, "html.parser")
        example_text = ""
    except:
        pass

    try:
        lsEN = soup.find_all("p",class_="qotCE")
        lsJP = soup.find_all("p",class_="qotCJ")
        for j in range(min(3,len(lsEN))):
            #print(lsJP[i].text.split("-")[0])
            #print(lsEN[i].text.replace("例文帳に追加",""))
            example_text += lsJP[j].text.split("-")[0] + "\n"
            example_text += lsEN[j].text.replace("例文帳に追加","") +"\n"
        example_text += "\n"
        example_list[i] = example_text
        #print(example_text)
        #data.iloc[i][2] = example_text
    except:
        print(word, "エラー発生")
    sleep(1.0)
 
 
data["example_sentences"] = example_list #格納
data.head(5)
 
data.to_csv("eiken1_reibun.csv") #csvとして出力
 
 

 

gameobjectはcomponentではないのね

MissingComponentException: There is no 'GameObject' attached to the "ThirdSaitenButton" game object, but a script is trying to access it.

 

のようにエラーが出たが解決したため備忘用

 

スクリプトから自身のgameObjectを扱いたい場合は

var obj =  this.GetComponent <GameObject>();

では取得できず、

 

var obj = gameObject と入力で取得できる。
あくまでGameObjectはコンポーネントではないため

this.Getcomponent<>()は使用できない。

 

 

参考

There is no GameObject attached to this GameObject - Unity Answers

ドイツ語検定4級・5級のAnkiデッキ

 

ドイツ語検定取得のため現在進めている単語帳の、Ankiデッキを作成したので共有してみようと思います。

 

参考元はこちらの書籍。

ネイティブの聞き流し音声、例文やコラムなども参考になるため、こちらを購入の上での使用をおすすめします。

 

独検5級・4級レベル重要単語1100

amzn.to

 

 

Anki共有デッキリンク

4級

https://ankiweb.net/shared/info/1317785971

5級

https://ankiweb.net/shared/info/892593228