擅长:python、mysql、java
<p>如果这真的是你要做的,你可以用<code>sed</code>和它的<code>-i</code>选项来重写文件:</p>
<pre><code>sed -e 's,href="/wiki,href="/home/fergus/wikiget/wiki,' wiki-file.html
</code></pre>
<p>但是,这里有一个使用可爱的<a href="http://lxml.de/" rel="nofollow">lxml</a>API的Python解决方案,以防您需要执行更复杂的操作,或者可能有格式错误的HTML等:</p>
^{pr2}$
<p>注意,<code>lxml</code>对于这类任务可能比BeautifulSoup更好,因为BeautifulSoup的作者给出了<a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html" rel="nofollow">reasons</a>。在</p>