<p>有办法提取吗</p>
<blockquote>
<p>Albert Einstein (/ˈælbərt ˈaɪnstaɪn/; German: ˈalbɐt ˈaɪnʃtaɪn; 14 March 1879– 18 April 1955) was a German-born theoretical physicist who developed the theory of general relativity, effecting a revolution in physics. ............. with over 150 non-scientific works. [6][8] His great intelligence and originality have made the word "Einstein" synonymous with genius. [9]</p>
</blockquote>
<p>(主段落的整个输出,如果代码运行,则可见)</p>
<p>自动从以下代码输出?即使它是从另一个维基百科页面输出的:</p>
<pre><code>import urllib2
import re, sys
from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(d)
def get_data(self):
return ''.join(self.fed)
def stripHTMLTags(html):
html = re.sub(r'<{1}br{1}>', '\n', html)
s = MLStripper()
s.feed(html)
text = s.get_data()
if "External links" in text:
text, sep, tail = text.partition('External links')
if "External Links" in text:
text, sep, tail = text.partition('External Links')
text = text = text.replace("See also","\n\n See Also - \n")
text = text.replace("*","- ")
text = text.replace(".", ". ")
text = text.replace(" "," ")
text = text.replace(""" /
/ ""","")
return text
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
infile = opener.open('http://en.wikipedia.org/w/index.php?title=Albert_Einstein&printable=yes')
page = infile.read()
print stripHTMLTags(page)
</code></pre>
<p>请原谅我糟糕的格式,代码(可能还有缩进),我现在使用的是3英寸显示器,还没有机会检查我自己的代码:p</p>
<p>也要感谢那些帮助我实现这一目标的人:)</p>