regex - Python - Split url into its components -


i have huge list of urls this:

http://www.example.com/site/section1/var1/var2 

where var1 , var2 dynamic elements of url. want extract url string var1. i've tried use urlparse output this:

parseresult(scheme='http', netloc='www.example.com', path='/site/section1/var1/var2', params='', query='', fragment='') 

alternatively, can apply split() method:

>>> url = "http://www.example.com/site/section1/var1/var2" >>> url.split("/")[-2:] ['var1', 'var2'] 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -