• 请不要在回答技术问题时复制粘贴 AI 生成的内容
0yster
V2EX  ›  程序员

万能的 v 友,请问 'module' object(urllib)has no attribute 'parse'时如何处理 url 中的中文?

  •  
  •   0yster · Mar 11, 2019 · 2776 views
    This topic created in 2630 days ago, the information mentioned may be changed or developed.

    pyversion=2.7.16 在给 hexo 博客写备份所有图片的脚本,由于发布的文章标题时常会有中文、英文、中英混杂的情况,而 hexo 博客文章的链接直接由时间和标题生成因而带了部分的中文。这种链接肯定要做处理。 查了一下别人用 urllib.parse.quote(url, safe=":/=?#")来处理字符串中部分的中文 但是莫名奇妙地报了如题的错

    于是改用正则 patt=re.compile('([\u4e00-\u9fa5]*?)') res=re.search(patt,posturl).group(1)

    结果发现匹配不到,想不明白哪里错了...

    只能过来求助 v 友了,求个解决方案

    2 replies    2019-03-12 00:36:24 +08:00
    GoLand
        1
    GoLand  
       Mar 11, 2019
    ```python
    import urlparse
    urlparse.urlparse(xxx)
    ```
    Arnie97
        2
    Arnie97  
       Mar 12, 2019 via Android
    因为别人用的是 Python 3,这个改名了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2846 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 06:03 · PVG 14:03 · LAX 23:03 · JFK 02:03
    ♥ Do have faith in what you're doing.