The following begins the construction of the HTTP packet,
The IP layer and TCP layer use Python's impacket Library, and the HTTP content is self-populated.
Copy the Code code as follows:
#!/usr/bin/env python
#--------------------------------------
Copy CodeThe code is as follows:
"""
If you only use the normal
Import Urllib.request
html = Urllib.request.urlopen ("http://www.sina.com"). Read ()
Print (Html.decode (' GBK '))
The following error occurredBuiltins. Unicodedecodeerror: ' GBK '
Copy CodeThe code is as follows:
Python 3.3.4 (v3.3.4:7ff62415e426, Feb, 18:13:51) [MSC v.1600-bit (AMD64)] on Win32
Type "Copyright", "credits" or "license ()" For more information.
>>> cast=["Cleese", "Palin", "Jones", "Idle"]
>>> Print (CAST)
['
The following is all about python2.7.
Copy the Code code as follows:
#coding: Utf-8
#chardet need to download the installation
Import Chardet#抓取网页htmlline = "Http://www.***.com"Html_1 = Urllib2.urlopen (line,timeout=120). Read ()#print
Copy CodeThe code is as follows:
Import Sys
Import Urllib
From Urllib Import Request
Import OS
From BS4 import BeautifulSoup
Class Dramaitem:
def __init__ (self, num, title, URL):
Self.num = num
Self.title = Title
Self.url = URL
def __str__ (self):
Example:
Copy the Code code as follows:
def re_escape (FN):Def arg_escaped (This, *args):t = [Isinstance (A, Verex) and A.S or Re.escape (str (a)) for a in args]RETURN FN (this, *t)Return arg_escaped
function nestingPython allows you to
Recently downloaded a lot of various tutorials, but unfortunately the suffix is ". mp4", and I like the ". rmvb" suffix, because of a slight cleanliness, can not stand behind the ". mp4" suffix, but manual modification is too cumbersome, so use the
One, the Python module xml.dom parsing XML API
Minidom.parse (filename)
Load read XML file
Doc.documentelementGet XML Document Object
Node.getattribute (AttributeName)Get XML Node Property value
Node.getelementsbytagname (TagName)Gets the
deleting files
Copy the Code code as follows:
Os.remove (filename) # filename: "File name to delete"
Possible causes of an exception:
(1) filename does not exist(2) The filename file has no operational permissions or is read-only.
Delete
The first method: recursion
Copy CodeThe code is as follows:
def perms (elements):
If Len (elements) Yield elements
Else
For Perm in Perms (elements[1:]):
For I in range (len (elements)):
Yield perm[:i] + elements[0:1] + perm[i:]
For item in list
A simple encapsulation of the Python Web request module URLLIB2.
Example:
Copy the Code code as follows:
#!/usr/bin/python
#coding: Utf-8
Import Base64
Import Urllib
Import Urllib2
Import time
Class SendRequest:'''The This class use to set and
Python crawler _ Collect associative Word code
Copy the Code code as follows:
#coding: Utf-8
Import Urllib2
Import Urllib
Import re
Import time
From random import choice
#特别提示, the proxy IP in the list below may be invalid, please change to a valid
Often use Python to detect whether the server can ping, whether the program is working properly (detect the appropriate port is normal)
The previous use of shell scripts is as follows:Copy the Code code as follows:
pingret=$ (ping www.baidu.com-c 2
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