<p>这些是我可能面临的问题</p>
<blockquote>
<p><a href="http://bla" rel="nofollow">http://bla</a> bla bla/?another bla bla bla</p>
<p><a href="http://bla" rel="nofollow">http://bla</a> bla bla/?another bla bla bla&page=3</p>
</blockquote>
<h3>我的问题</h3>
<p>我想带走你</p>
<blockquote>
<p><a href="http://bla" rel="nofollow">http://bla</a> bla bla/?another bla bla bla</p>
</blockquote>
<h3>我尝试的</h3>
<pre><code>re.match("(.*)^&page=+\d",value).group(1)
</code></pre>
<p>其中<code>value</code>是具有字符串值的prameter</p>
<p>但我得到:</p>
<pre><code>AttributeError: 'NoneType' object has no attribute 'group'
</code></pre>
<p>我知道原因(正则表达式是错误的),但我不知道解决方法</p>
<p>这里不需要使用正则表达式,只需简单地应用字符串操作即可</p>
<pre><code>value = 'http://bla bla bla/?another bla bla bla&page=3'
index = value.find(r'&page=')
if index > 0:
result = value[:index]
else:
result = value
</code></pre>