Search code examples
pythonstringsplitdivide

Python Divide a string


I have a string like this:

 <td casd2" aasdeft" class="satyle3">
    <b><a asddidasd?ct=Peasds&amp;fasdaao=Monsdar
    &amp;pID=19635"...

I need the 19635.

Someone can help me ?


Solution

  • I would use regular expressions to make a more neat solution:

    >>> import re
    >>> s = '<td casd2" aasdeft" class="satyle3"><b><a asddidasd?ct=Peasds&amp;fasdaao=Monsdar&amp;pID=19635"...'
    >>> match = re.search(".*pID=(\d+).*",s)
    >>> if match:
    ...   match.group(1)
    ... 
    '19635'
    

    Nice and simple isn't it?