擅长:python、mysql、java
<p>试试这个:</p>
<pre><code>actuallink = 'http://www.exxonmobilperspectives.com'
slashcounter = 0
indexslash = 0
while indexslash < len(actuallink):
if(actuallink[indexslash] == '/'):
slashcounter = slashcounter + 1
print("Slash number {},Index ={}".format(slashcounter,indexslash))
indexslash = indexslash + 1
PLink = actuallink[:indexslash - 1]
print("Slashcounter = {}".format(slashcounter))
</code></pre>
<p>结果是:</p>
<pre><code>Slash number 1,Index =5
Slash number 2,Index =6
Slashcounter = 2
</code></pre>