【问题标题】:How to turn an encoded link such as "http%3A%2F%2Fexample.com%2Fwhatever" into "http://example.com/whatever" in python?如何在python中将“http%3A%2F%2Fexample.com%2Fwhatever”等编码链接转换为“http://example.com/whatever”?
【发布时间】:2011-04-17 21:16:55
【问题描述】:

我总是在 html 源代码中找到以这种格式存储的链接,问题是如何将这些链接改回正常的样子?

非常感谢!

【问题讨论】:

    标签: python html


    【解决方案1】:

    【讨论】:

    • @Shane:如果这是您正在寻找的答案。也请接受答案。
    • @pyfunc: 我一看到这个答案就打算接受这个答案,但我不被允许...所以不得不稍后返回接受这个答案...
    【解决方案2】:

    urllib.unquote() 本身仍然可能通过抛出异常导致问题:

    UnicodeDecodeError:“ascii”编解码器无法解码位置 n 中的字节 0xc3:序数不在范围内 (128)

    在这种情况下尝试: print urllib.unquote("Ober%C3%B6sterreich.txt").decode("utf8")

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2014-02-25
      • 2019-12-12
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2015-05-21
      相关资源
      最近更新 更多