python - 為什麼提取不到url編碼的資料?
过去多啦不再A梦
过去多啦不再A梦 2017-05-18 11:00:01
0
1
831

這是我的程式碼

            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梦

全部回覆(1)
滿天的星座

r'[%w]+'

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板