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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World