python - Get value from a dynamic url -
my url looks like:
http://www.example.com/blah/prod/4/x/blah.html
now if page has sub-pages, like:
http://www.example.com/blah/prod/4_2343/x/blah.html
i.e. after /prod/4 there underscore number.
again if page has sub-pages, be:
http://www.example.com/blah/prod/4_2343_234/x/blah.html
i need text put ??? below:
/prod/???????/x/blah.html
how can this?
for example this. regexp matches pattern prod/???/x/blah, ??? string consisting of numbers , underscores:
import re pattern = re.compile('prod/([\d_]+)/x/blah') query = "http://www.example.com/blah/prod/4_2343_234/x/blah.html" result = pattern.search(query).group(1) print result
Comments
Post a Comment