编写脚本,以循环方式获取网页的特定部分以供脱机使用

|| 我有特定用途。我正在为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>
但网页呈现如下: •(adj。)没有足够的钱支付必需品 同义词:努力,在困境中,身无分文,忧郁,紧张     
已邀请:
如果您有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
    
从Bash外壳(Linux,Mac或Windows和Cygwin)使用curl和sed。 如果我有机会的话,我会写一个快速的剧本……现在要给婴儿洗澡。     

要回复问题请先登录注册