Python: Get URL path sections

后端 未结 7 1599
长发绾君心
长发绾君心 2020-12-01 05:15

How do I get specific path sections from a url? For example, I want a function which operates on this:

http://www.mydomain.com/hithere?image=2934

7条回答
  •  春和景丽
    2020-12-01 05:34

    import urlparse
    
    output = urlparse.urlparse('http://www.example.com/temp/something/happen/index.html').path
    
    output
    
    '/temp/something/happen/index.html'
    
    Split the path -- inbuilt rpartition func of string 
    
    output.rpartition('/')[0]
    
    '/temp/something/happen'
    

提交回复
热议问题