我尝试使用以下示例代码以获取一个网页: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