1

I have this url

www.testing.com/drive/rayon.productlist.pagination.topage/2?t:ac=3686975/4441810

and i want to have 2

i tried this in python 2.7:

s = 'www.testing.com/drive/rayon.productlist.pagination.topage/2?t:ac=3686975/4441810'
s = s.substring(s.indexOf("topage/") + 1);
s = s.substring(0, s.indexOf("?"));
print s

and i got this error

AttributeError: 'str' object has no attribute 'substring'

3 Answers 3

1

You should use the urlparse function if you need different component of an URL.

>>> from urlparse import urlparse
>>> u = urlparse("www.testing.com/drive/rayon.productlist.pagination.topage/2?t:ac=3686975/4441810")
>>> u
ParseResult(scheme='', netloc='', path='www.testing.com/drive/rayon.productlist.pagination.topage/2', params='', query='t:ac=3686975/4441810', fragment='')
>>> u.path[-1]
'2'
>>> 
Sign up to request clarification or add additional context in comments.

Comments

0

The answer is:

s = 'www.testing.com/drive/rayon.productlist.pagination.topage/2?t:ac=3686975/4441810'
    s =     s[:s.index("?")]
    s = s[-1:]
    print s

Comments

0
In [62]:  s = 'www.testing.com/drive/rayon.productlist.pagination.topage/2?t:ac=3686975/4441810'

In [63]: s[s.index("topage/")+ len('toppage'):s.index("?")]
Out[63]: '2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.