0

特定の用途があります。GREの準備をしています。新しい単語が登場するたびに、www.mnemonicdictionary.com でその意味とニーモニックを調べます。テキストファイルから単語のリストを取得し、それを検索するスクリプトをPythonで作成したい(または、Pythonをあまり知らないが、現在学習しているため、誰かが既存のものへのポインタを提供できる場合)このサイトで、関連する部分 (意味とニーモニック) を取得し、オフラインで使用するために別のテキスト ファイルに保存します。そうすることは可能ですか?? これらのページのソースも調べてみました。ただし、html タグとともに、いくつかの ajax 関数もあります。誰かがこれを行う方法を完全に教えてくれますか??

例: 無礼な単語の場合:

関連するhtmlソースはこんな感じ

<ul class='wordnet'><li><p>(adj.)&nbsp;not having enough money to pay for necessities</p><u>synonyms</u> : <a href='http://www.mnemonicdictionary.com/word/hard up' onclick="ajaxSearch('hard up','click'); return false;">hard up</a> , <a href='http://www.mnemonicdictionary.com/word/in straitened circumstances' onclick="ajaxSearch('in straitened circumstances','click'); return false;">in straitened circumstances</a> , <a href='http://www.mnemonicdictionary.com/word/penniless' onclick="ajaxSearch('penniless','click'); return false;">penniless</a> , <a href='http://www.mnemonicdictionary.com/word/penurious' onclick="ajaxSearch('penurious','click'); return false;">penurious</a> , <a href='http://www.mnemonicdictionary.com/word/pinched' onclick="ajaxSearch('pinched','click'); return false;">pinched</a><p></p></li></ul>

しかし、Web ページは次のようにレンダリングされます。

•(形容詞) 必需品の支払いに十分なお金がない

4

2 に答える 2

3

Bash (バージョン 4+) とを使用wgetしている場合、例

#!/bin/bash
template="http://www.mnemonicdictionary.com/include/ajaxSearch.php?word=%s&event=search"
while read -r word
do
    url=$(printf "$template" "$word")
    data=$(wget -O- -q "$url")
    data=${data#*&nbsp;}
    echo "$word: ${data%%<*}"
done < file

サンプル出力

$> more file
synergy
tranquil
jester

$> bash dict.sh
synergy: the working together of two things (muscles or drugs for example) to produce an effect greater than the sum of their individual effects
tranquil: (of a body of water) free from disturbance by heavy waves
jester: a professional clown employed to entertain a king or nobleman in the Middle Ages

更新: ニーモニックを含める

template="http://www.mnemonicdictionary.com/include/ajaxSearch.php?word=%s&event=search"
while read -r word
do
    url=$(printf "$template" "$word")
    data=$(wget -O- -q "$url")
    data=${data#*&nbsp;}
    m=${data#*class=\'mnemonic\'}
    m=${m%%</p>*}
    m="${m##*&nbsp;}"
    echo "$word: ${data%%<*}, mneumonic: $m"    
done < file
于 2011-04-21T01:16:39.047 に答える
1

Bash シェル (Linux、Mac、または Cygwin を使用した Windows) からcurlおよび sed を使用します。

ちょっと時間があれば、簡単なスクリプトを書きます...でも、今すぐ赤ちゃんをお風呂に入れなければなりません。

于 2011-04-21T01:01:56.113 に答える