Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

为什么提取不到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

正则写错了吗?还是哪里错了?要怎么修改


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

r'[\%w]+'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...