简体   繁体   English

避免在python中搜索程序的文本文件中进行十六进制编码

[英]Avoid hex-encoding in a text-file for a searching program in python

I have written a python program to analyze a server log(a text file) and to find non matching strings to a user input. 我编写了一个python程序来分析服务器日志(文本文件)并找到不匹配的字符串到用户输入。 Anyway hex-encoded strings are not considered by the program. 无论如何,程序不考虑十六进制编码的字符串。 Ex : In the following case the program says that there are no non-matching values to the user input although 'www.peoplesmonton.com' is available. 例如:在以下情况下,程序表示尽管“www.peoplesmonton.com”可用,但用户输入没有不匹配的值。 Please help me to avoid this? 请帮我避免这个?

for line in lines:
    match = re.search('\\b' + userinput + '\\b',line)

sample text file: 示例文本文件:

https://www.mysite.com/myworks/accaply/inquiry.asp 
http://www.peoplesmonton.com/amb/cgi-bin/bank/bank/ambt%20Bank%20Of%20Frnak%20PLC_asp.htm 
http://www.peoplesmonton.com/comblk/cgi-bin/bank/bank/ambt%20Bank%20Of%20ambt%20PLC_asp.htm 

The information is URL encoded , so use urllib2.unquote to decode that. 信息是URL编码的 ,因此请使用urllib2.unquote进行解码。

>>> input = '''\
... https://www.mysite.com/myworks/accaply/inquiry.asp 
... http://www.peoplesmonton.com/amb/cgi-bin/bank/bank/ambt%20Bank%20Of%20Frnak%20PLC_asp.htm 
... http://www.peoplesmonton.com/comblk/cgi-bin/bank/bank/ambt%20Bank%20Of%20ambt%20PLC_asp.htm 
... '''
>>> import urllib2
>>> print urllib2.unquote(input)
https://www.mysite.com/myworks/accaply/inquiry.asp 
http://www.peoplesmonton.com/amb/cgi-bin/bank/bank/ambt Bank Of Frnak PLC_asp.htm 
http://www.peoplesmonton.com/comblk/cgi-bin/bank/bank/ambt Bank Of ambt PLC_asp.htm 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM