save url as a file name in python

后端 未结 5 854
暖寄归人
暖寄归人 2021-01-06 07:32

Firstly, I\'m pretty new in python, please leave a comment as well if you consider to down vote

I have a url such as

http://example.com/here/there/         


        
5条回答
  •  轮回少年
    2021-01-06 07:59

    You could use the reversible base64 encoding.

    >>> import base64
    >>> base64.b64encode('http://example.com/here/there/index.html')
    'aHR0cDovL2V4YW1wbGUuY29tL2hlcmUvdGhlcmUvaW5kZXguaHRtbA=='
    >>> base64.b64decode('aHR0cDovL2V4YW1wbGUuY29tL2hlcmUvdGhlcmUvaW5kZXguaHRtbA==')
    'http://example.com/here/there/index.html'
    

    or perhaps binascii

    >>> binascii.hexlify(b'http://example.com/here/there/index.html')
    '687474703a2f2f6578616d706c652e636f6d2f686572652f74686572652f696e6465782e68746d6c'
    >>> binascii.unhexlify('687474703a2f2f6578616d706c652e636f6d2f686572652f74686572652f696e6465782e68746d6c')
    'http://example.com/here/there/index.html'
    

提交回复
热议问题