搜尋

首頁  >  問答  >  主體

python - 為什麼提取不到url編碼的資料?

這是我的程式碼

            source_ip = line.split(' ')[11].strip()
            if re.match('[\%\w]+',source_ip):
                if source_ip_dict.get(source_ip,'-')=='-':
                    source_ip_dict[source_ip]=1
                else:
                    source_ip_dict[source_ip]=source_ip_dict[source_ip]+1

這是日誌裡面的資料

106.39.191.230 - - [20/Apr/2017:15:41:06 +0800] 0 "GET /article/1056 HTTP/1.1" 302 - "https://so.m.sm.cn/s?q=%E5%B0%8F%E7%BD%90%E8%8C%B6+%E5%90%A7&uc_param_str=dnntnwvepffrgibijbprsvdsme&from=ucframe&by=submit&snum=9&uc_sm=1" "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; MI 5 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.4.5.937 Mobile Safari/537.36"
183.11.69.39 - - [20/Apr/2017:16:41:10 +0800] 0 "GET /article/810 HTTP/1.1" 200 8567 "https://www.sogou.com/link?url=DSOYnZeCC_oEIb3cp8Q2nRzAwnn3W-dXaJrgRIXUqR540kn4PqPKYQ..&query=%E5%93%81%E8%8C%B6%E5%94%AF%E7%BE%8E%E6%84%8F%E5%A2%83%E5%9B%BE%E7%89%87" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2604.400 QQBrowser/9.6.10875.400"
183.224.69.81 - - [20/Apr/2017:16:53:18 +0800] 0 "GET /article/514441 HTTP/1.1" 200 11327 "http://www.so.com/link?url=http%3A%2F%2Fwww.testurl.com%2Farticle%2F514441&q=%E5%A4%A7%E7%9B%8A%E5%AE%9D%E7%9B%92&ts=1492678364&t=40b441f225a931eddb35fbcd0bc8a3c&src=haosou" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"

為什麼提取不到

%E5%A4%A7%E7%9B%8A%E5%AE%9D%E7%9B%92
%E5%93%81%E8%8C%B6%E5%94%AF%E7%BE%8E%E6%84%8F%E5%A2%83%E5%9B%BE%E7%89%87
%E5%B0%8F%E7%BD%90%E8%8C%B6+%E5%90%A7

正規寫錯了嗎?還是哪裡錯了?怎麼修改

过去多啦不再A梦过去多啦不再A梦2779 天前834

全部回覆(1)我來回復

  • 滿天的星座

    滿天的星座2017-05-18 11:02:01

    r'[%w]+'

    回覆
    0
  • 取消回覆