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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -