This article is divided into two examples. The first example is a simple example of crawling a website. The second example is to capture the article list from the list page of a website and store it in the database, the database includes the article
Python gets hundreds of image code instances. for details, refer to the following code:
From sgmllib import SGMLParserImport urllib2
Class sgm (SGMLParser ):Def reset (self ):SGMLParser. reset (self)Self. srcs = []Self. ISTRUE = True
Def
In a Python program, each data is an object, and each object has its own type. Different types of operations have different methods. using the built-in data type exclusive operation method can accomplish a lot of work faster.
What are the basic
This section describes how to use python and go to directly save the output of other programs as variables for the program, for your reference, you can use the system function in the C language to call system commands and get the output. you can
This article describes how to compare the content of two text files in Python. if the content is different, the first line number and column number in different places are given. for details, refer to the following code:
# Compare two strings. if
Develop a program to obtain the list of host IP addresses that enable the snmp service in the LAN, and write the corresponding files for other programs to use. The following is an overview of implementation method 1.
Task description:
Develop a
Use tkinter to create a small window with two buttons, one btn to close the window, and the other btn to switch and execute the two passed functions. simple small code can be used for your reference.
The code is as follows:
Import timeImport
This article mainly introduces an example of how to calculate the number of lines in python code. For more information, see the following code:
#! /Usr/bin/python
'''File: count. pyAuthor: MikeE-mail: Mike_Zhang@live.com'''Import sys, OS
Extens = ["
Many software have configuration files. today we will introduce how to use the parsing configuration file of the pythonConfigParser module to test the configuration file test. conf. the content is as follows:
The code is as follows:
[First]W = 2V:
Due to work needs, I studied the simulation of Baidu login and used python3 in the development environment. for details, refer to the following code:
#-*-Coding: UTF-8 -*-'''Created on January 10, 2014
@ Author: hhdys'''Import urllib. request, http.
The following python code can launch denial-of-service (DoS) attacks on web servers:
#-*-Coding: cp936 -*-From scapy. all import *From threading import Thread, activeCountFrom random import randint
Class Loop (Thread ):Def _ init _ (self,
This article mainly introduces the bitwise operators in Python. if you need them, you can refer to the bitwise operators that regard numbers as binary for calculation. The bitwise algorithm in Python is as follows:
Bitwise and of x and y)
&
This article mainly introduces the Python sys module. path usage. for details, refer to the python sys module that contains functions related to the python interpreter and its environment. you can use dir (sys) to view its methods and member
The easy_install tool in python is similar to pear in Php, gem in Ruby, or cpan in Perl. it is quite cool. if you want to use the easy_install tool, you may need to install setuptools first, but the cool way is to use the ez_setup.py script:
The
This article mainly introduces three methods for reading file content line by line in python, which is very simple. let's look at the code. Method 1:
The code is as follows:
F = open ("foo.txt") # returns a file objectLine = f. readline () #
Various sorting algorithms implemented by python, including selection, bubble sorting, Insertion sorting, and merge sorting. for python users, refer to the following code:
#-*-Coding: UTF-8 -*-# Test various sorting algorithms# Link: www.bitsCN.com#
The mako template in ylons introduces a helper object by default. we can expand the method in it to cope with common operations during template output, in Pyramid, how to introduce the same helper class to the template by default? the principle is
After CentOS5.9 (Final) is installed, run # Python and # python-V. you can see that the version number is 2.4.3, which is very old. what you wrote earlier is running on python3.X. 3. X and 2. X has many differences. if you are interested, you can
This article describes how to parse XML files using python.
The code is as follows:
Def get_area_list (self ):"Retrieve region, province, and City name dictionaries """Page = urllib2.urlopen (self. xml_url). read ()Area_list = {}Root =
This article mainly introduces the code for implementing system status monitoring and failover using python as follows:
# Coding: UTF-8Import socketImport selectImport timeImport OSImport threading
Def ser ():S = socket. socket (socket. AF_INET,
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