Topic: How to parse Web access logs using PythonContent
Python Basics
string, dictionary, file, time
Web Access Logs
Actual combat
Questions
Main lecturer: KKMulti-language mashup engineer, love open
In Python, there is a difference between the assignment of an object and the copy (deep/shallow copy), which can produce unexpected results if used without notice.assigning values to ObjectsLook directly at the code:would = ["would", +, ["Python",
First, the basic knowledge
There are two ways to run Python:
The first is run through interactive operation, through "start", "All Programs", "python3.x", "IDLE".
The second is that we write the Python file double-click Run.
When the website is really a picture, often encounter the problem of incomplete picture link.For example, the case is as follows:The image link in the IMG tag is incomplete, if the site domain name is a variety of circumstances, such asHttp://sports.
insist on blogging to record the learning process, even if you learn how simple! The following is the CGI-related knowledge in Python. Template.py:(Template engine file)#模板引擎DefStart_response (resp="Text/html"): Return' Content-type: ' +resp+‘\ n‘
1, the definition of the Python dictionary1. Use curly braces {}, separate each key-value pair with a comma, and connect the key to the value with a colon2, Key: Need immutable data structure, the value can be arbitrary data object3, the dictionary
cyclic structure (for-in)
Description: Also a loop structure, often used to traverse strings, lists, tuples, dictionaries, etc.
Format:Y:Loop bodyExecution process: X in turn represents an element in Y, traversing through all elements loop end
Part 12 BinarySlightlyPart 2 character encoding and computer capacity1.ascii yards2. Computer capacity1 bit = 1bitBit is the smallest storage unit in the computer;8bit = 1 bytes (Bytes)Every single character in the ASCII code table requires 8 bits,
Import Urllib.request#urllib. Request.urlopen can pass in a URL or request object#req =urllib.request.request ("http://placekitten.com/g/500/600")#response =urllib.request.urlopen (req)#response的geturl, info (), GetCode () Get status, 200 indicates
Nonsense less say, on the code:1 ImportMatplotlib as Mpl2Mpl.use ('Agg')3 4 ImportOS5 ImportMatplotlib.pyplot as Plt6 fromScipy.miscImportimresize7 8 #root path depends on your computer9ROOT1
When we make the IF = = judgment!The conditions in which to judge:1: The value is not the same2: Whether the memory address is the same3: Whether the type is the same# # #三者少了任何一个都不可以User_list = [{' Name ': ' alxe ', ' password ': 123}]current_list =
#coding:utf-8
import
binascii
a
=
‘worker‘
#先把worker转换成二进制数据然后在用十六进制表示
b
=
binascii.b2a_hex(a)
print
b
#与b2a_hex相反
print
binascii.a2b_hex(b)
#这个功能和b2a_hex()一样
c
=
binascii.hexlify(a)
print
c
When crawling page content, it is important to understand the encoding used by the target site, and this article describes several common methods and uses several sites for simple testing.Code Run Result:From the test results of several websites in
First, demand:There are two files similar to the following which need to be compared and processed. 1.txt1231 2.txtABCDSecond, the question:The first thing to think about is when you open it, two times for the loop.#错误写法f1=open(r"D:\pytest\1.
Inherited:Inheritance is a way of creating new classes,In Python, a new class can inherit one or more parent classes (base or superclass), and the new class is the inherited class (derived class or subclass)Humans and dogs have the same attributes,
1, please use the code to achieve: the use of underline the list of each element of the mosaic into a string, li=[' Alex ', ' Eric ', ' rain 'l1=['Alex'Eric'rain' Print('%s_%s_%s'% (l1[0],l1[1],l1[2))l1=['Alex','Eric','rain' n="_". Join (L1)print(n)
Output: ++++++++++++ ++++++++++++1 Print("+++++++++++")2 Print("+ +")3 Print("+++++++++++")4 5 6 Print("+"*11)7 Print("+"+" "*9+"+")#Plus a plus space multiplied by nine plus a plus sign8 Print("+"*11)Small essay:# notation 1: direct with \
Python learning path ----- serialization, python ----- serialization
The process of changing variables from memory to storage or transmission is called serialization. in Python, it is called pickling. In other languages, it is also called
Python3 sends emails via QQ mail and python3 sends emailsPython3 send emails via QQ mail 0. Learn about SMTP in QQ mail
Set POP3 and SMTP server addresses in QQ mail as follows:
Email
POP3 server (Port 995)
SMTP server (Port 465 or 587
Use Python to analyze the gender and location of friends and python gender
A very interesting library is used today --ItchatIt has completed wechat's personal account API, making it easier to crawl personal information.
Download
Crawl friend
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service