我需要建立一个有文章的网站,我想为它制作友好的URL,例如页面的URL
标题:文章测试
应该成为:http://www.example.com/articles/article_test.
当然我需要删除标题中的一些字符,?或者#,但我不确定要删除哪些字符.
谁能告诉我哪些角色可以保存?
我想根据 url 将 html 保存到文件中。
为 url 获取唯一名称我正在使用 uuid。
>>> url = "https://www.google.co.in/?gfe_rd=cr&ei=-koUWPf4HqzT8ge2g6HoBg&gws_rd=ssl"
>>> uuidstring = str(uuid.uuid5(uuid.NAMESPACE_DNS, url))
Run Code Online (Sandbox Code Playgroud)
但我想进一步缩短名称。有什么方法可以将字符串缩短为唯一的小字符串。
我尝试过 base64,但我无法弄清楚。
>>> uuid.UUID(uuidstring).bytes.encode('base64').rstrip('=\n').replace('/', '_')
>>> AttributeError: 'bytes' object has no attribute 'encode'
Run Code Online (Sandbox Code Playgroud)