我嘗試使用以下示例代碼以獲取一個網頁:Python的正則表達式切片
from urllib import urlopen
print urlopen("http://www.php.net/manual/en/function.gettext.php").read()
現在,我可以得到整個網頁中的變量。我想獲得的包含網頁的東西的一部分這樣
<div class="methodsynopsis dc-description">
<span class="type">string</span><span class="methodname"><b>gettext</b></span> (<span class="methodparam"><span class="type">string</span> <tt class="parameter">$message</tt></span>
)</div>
,這樣我可以生成一個文件在其他應用程序來實現。 我想要能夠提取單詞「字符串」,「gettext」和「$消息」。
這個問題的變化已經被問了很多次的SO。這是最權威的答案:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2010-09-25 07:53:17