473,748 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RE: Extract string from log file

from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below...

import urllib
line = "GET /stat.gif?stat=v &c=F-Secure&v=1.1%20 Build%2014231&s =av%7BNorton%20 360%20%28Symant ec%20Corporatio n%29+69%3B%7Dsw %7BNorton%20360 %20%28Symantec% 20Corporation%2 9+69%3B%7Dfw%7B Norton%20360%20 %28Symantec%20C orporation%29+5 %3B%7Dv%7BMicro soft%20Windows% 20XP+insecure%3 BMicrosoft%20Wi ndows%20XP%20Pr ofessional+f%3B 26027%3B26447%3 B26003%3B22452% 3B%7D&r=0.9496 HTTP/1.1"
words = line.split()
for word in words:
if word.find('?') >= 0:
req = word[word.find('?') + 1:]
kwds = req.split('&')
for kv in kwds:
print urllib.unquote( kv)
stat=v
c=F-Secure
v=1.1 Build 14231
s=av{Norton 360 (Symantec Corporation)+69 ;}sw{Norton 360 (Symantec Corporation)+69 ;}fw{Norton 360 (Symantec Corporation)+5; }v{Microsoft Windows XP+insecure;Mic rosoft Windows XP Professional+f; 26027;26447;260 03;22452;}
r=0.9496

good luck
Edwin

-----Original Message-----
From: py************* *************** *************** *******@python. org
[mailto:py****** *************** *************** **************@ python.org]
On Behalf Of jo*********@goo glemail.com
Sent: Saturday, August 09, 2008 10:48 AM
To: py*********@pyt hon.org
Subject: Extract string from log file
203.114.10.66 - - [01/Aug/2008:05:41:21 +0300] "GET /stat.gif?
stat=v&c=F-Secure&v=1.1%20 Build%2014231&s =av%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+69%3B%7 Dsw%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+69%3B%7 Dfw%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+5%3B%7D v%7BMicrosoft%2 0Windows
%20XP+insecure% 3BMicrosoft%20W indows%20XP%20P rofessional+f
%3B26027%3B2644 7%3B26003%3B224 52%3B%7D&r=0.94 96 HTTP/1.1" 200 43
"http://dfstage1.f-secure.com/fshc/1.1/release/devbw/1.1.14231/
card.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)"

does anyone know how can i extract certain string from this log file
using regular expression in python or using XML. can teach me.
--
http://mail.python.org/mailman/listinfo/python-list
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Aug 9 '08 #1
1 2725
On Aug 9, 11:22*pm, Edwin.Mad...@Ve rizonWireless.c om wrote:
from each line separate out url and request parts. split the request intokey-value pairs, use urllib to unquote key-value pairs......as show below....

import urllib
line = "GET /stat.gif?stat=v &c=F-Secure&v=1.1%20 Build%2014231&s =av%7BNorton%20 360%20%28Symant ec%20Corporatio n%29+69%3B%7Dsw %7BNorton%20360 %20%28Symantec% 20Corporation%2 9+69%3B%7Dfw%7B Norton%20360%20 %28Symantec%20C orporation%29+5 %3B%7Dv%7BMicro soft%20Windows% 20XP+insecure%3 BMicrosoft%20Wi ndows%20XP%20Pr ofessional+f%3B 26027%3B26447%3 B26003%3B22452% 3B%7D&r=0.9496 HTTP/1.1"
words = line.split()
for word in words:
if word.find('?') >= 0:
* * * * req = word[word.find('?') + 1:]
* * * kwds = req.split('&')
* * * for kv in kwds:
* * * * print urllib.unquote( kv)

stat=v
c=F-Secure
v=1.1 Build 14231
s=av{Norton 360 (Symantec Corporation)+69 ;}sw{Norton 360 (Symantec Corporation)+69 ;}fw{Norton 360 (Symantec Corporation)+5; }v{Microsoft Windows XP+insecure;Mic rosoft Windows XP Professional+f; 26027;26447;260 03;22452;}
r=0.9496

good luck
Edwin

-----Original Message-----
From: python-list-bounces+edwin.m adari=verizonwi reless....@pyth on.org

[mailto:python-list-bounces+edwin.m adari=verizonwi reless....@pyth on.org]
On Behalf Of josephty...@goo glemail.com
Sent: Saturday, August 09, 2008 10:48 AM
To: python-l...@python.org
Subject: Extract string from log file

203.114.10.66 - - [01/Aug/2008:05:41:21 +0300] "GET /stat.gif?
stat=v&c=F-Secure&v=1.1%20 Build%2014231&s =av%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+69%3B%7 Dsw%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+69%3B%7 Dfw%7BNorton
%20360%20%28Sym antec%20Corpora tion%29+5%3B%7D v%7BMicrosoft%2 0Windows
%20XP+insecure% 3BMicrosoft%20W indows%20XP%20P rofessional+f
%3B26027%3B2644 7%3B26003%3B224 52%3B%7D&r=0.94 96 HTTP/1.1" 200 43
"http://dfstage1.f-secure.com/fshc/1.1/release/devbw/1.1.14231/
card.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)"

does anyone know how can i extract certain string from this log file
using regular expression in python or using XML. can teach me.
--http://mail.python.org/mailman/listinfo/python-list

The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. *If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. *Thank you.

do you mind to explain further. based on the source code that you gave
me. what will it output. i wonder. Sorry i am new to string
extraction. i do understand your python coding. the only thing i don't
understand is this part.
for word in words:
if word.find('?') >= 0:
req = word[word.find('?') + 1:]
kwds = req.split('&')
for kv in kwds:
print urllib.unquote( kv)

what does this code do?
anyway, is this code automatic. what i mean is can it extract the
string everytime when a new log file is being output by the sever?
Aug 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
16982
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and extract 35 characters (including "T") from a file and then go to next line?
6
10509
by: Mohammad-Reza | last post by:
Hi I want to extract icon of an exe file and want to know how. I look at the MSDN and find out that I can use ExtractIconEx() Windows API but in there are some changes to that api in c# I made those changes like this : public static extern uint ExtractIconEx( string szFile,
8
6059
by: nick | last post by:
Hi all can any one please tell me what is wrong in this code?? I'm new to deal with text files and extract data. i'm trying to look for data in a text file (3~4 pages) some lines start with a word "red" first if find(red) then print the last 5 letters of that string and if red is not found at the begining of the string then do nothing and go to another line. how can I also do this using find( )??
5
5120
by: deko | last post by:
If I have random and unpredictable user agent strings containing URLs, what is the best way to extract the URL? For example, let's say the string looks like this: registered NYSE 943 <a href="http://netforex.net"Forex Trading Network Organization </ainfo@netforex.org What's the best way to extract http://netforex.net ?
1
3663
by: nkg1234567 | last post by:
I'm trying to extract HTML from a website in the form of a string, and then I want to extract particular elements from the string using the substr function: here is some sample code that I have thus far: use HTTP::Request::Common; use LWP::UserAgent; use LWP::Simple; $ua = LWP::UserAgent->new;
7
7645
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and can't seem to figure it out. Here is what I have so far. p = POP3("mail.server.com")
0
2049
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-E Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file.
3
3928
by: learningvbnet | last post by:
Hi, I am trying to extract zipped files using Winzip in my VB.net application and I ran into 2 stone walls. 1. How do you handle file names with spaces. See psiProcess.Arguments For example "My Data file Apr2007.zip"? In the example below, the parameter pZippedFile contains the file name with spaces and the pExtractFolder contains the folder where it should be extracted. 2. Is there anyway to get the extracted...
5
5763
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to extract the image of the document (just the first page if there are multiple pages) and save it as a TIFF so I can then use the Tesseract OCR to get the text in the image.
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.