= { "user-agent":"mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) gecko/20100101 firefox/50.0", "Referer":"http://tieba.baidu.com/f?kw=%E4%BF%9D%E5%AE%9Aie=utf-8pn=50"}request= Urllib2. Request (url=url,data=data,headers=header) Response=Urllib2.urlopen (Request)PrintResponse.read ()View CodeUrlopen is urllib2. An instance of Openerdirector, a opener, a special default opener. Therefore, this
, provides the most basic method, Defult_open (), protocol_request (), etc.Various inherited handler subclasses of this Basehandler parent class:
Httpdefaulterrorhandler: for handling HTTP response errors, errors will throw exceptions of type Httperror
Httpredirecthandler: Handling redirects
Httpcookieprocessor: Handling Cookies
Proxyhandler: Set proxy, default proxy is empty
Httppasswordmgr: Manage password, maintain the user name and password of the table
Httpbasic
There are a number of useful tools classes in the Python standard library, but when used specifically, the standard library documentation does not describe the details of the usage, such as URLLIB2 this HTTP client library. Here is a summary of some of the URLLIB2 library usage details.
1 setting of Proxy
URLLIB2 uses environment variable HTTP_PROXY to set HTTP proxy by default. If you want to explicitly control the Proxy in your program without being affected by the environment variables, you
The basic method of python crawlers and python Crawlers
1. the most basic website capture import urllib2content = urllib2.urlopen ('HTTP: // xxxx '). read ()-2. using a proxy server is useful in some situations, such as the IP address being blocked or the number of times the IP address is accessed is limited. Import urllib2proxy_support = urllib2.ProxyHandler ({'http': 'http: // XX. XX. XX. XX: xxxx'}) opener = urllib2.build _
Hello, everybody. In the last section we studied the problem of the abnormal handling of reptiles, so let's take a look at the use of cookies.
Why use cookies?
Cookies, which are data stored on the user's local terminal (usually encrypted) by certain websites in order to identify users and perform session tracking.
For example, some sites need to log in to access a page, before you log in, you want to crawl a page content is not allowed. Then we can use the URLLIB2 library to save our registere
real URL, which is useful because urlopen (or opener object) MayThere will be redirection. The obtained URL may be different from the requested URL.Info -- the dictionary object of the returned object, which describes the page information obtained. It is usually the specific headers sent by the server. Currently, this is an httplib. HTTPMessage instance.The classic headers include "Content-length", "Content-type", and others. View Quick Reference to
variables obtained from the new window are indeed retained and still take effect. Because we reference it, even if the window is closed, its memory will not be recycled.
In reality, you can bind the click event to the document, so that you can trigger any click anywhere to obtain a pure environment.
Therefore, we have to use the pop-up function to protect it through hooks.
In addition to the most commonly used window. open, there are:
ShowModalDialog
ShowModelessDialog
window are indeed retained and still take effect. Because we reference it, even if the window is closed, its memory will not be recycled.
In reality, you can bind the click event to the document, so that you can trigger any click anywhere to obtain a pure environment.
Therefore, we have to use the pop-up function to protect it through hooks.
In addition to the most commonly used window. Open, there are:
Showmodaldialog
Showmodelessdialog
Opener
If
couldn \'t fulfill the request. 'print 'error code: ', E. codeelse: # Everything is fine
Info and geturlThe response object response (or httperror instance) returned by urlopen has two useful methods: Info () and geturl ()Geturl -- returns the obtained real URL, which is useful because urlopen (or opener object) MayThere will be redirection. The obtained URL may be different from the requested URL.Info -- the dictionary object of the returne
real URL, which is useful because urlopen (or opener object) MayThere will be redirection. The obtained URL may be different from the requested URL.
Info -- the dictionary object of the returned object, which describes the page information obtained. It is usually the specific headers sent by the server. Currently, this is an httplib. httpmessage instance.
The classic headers include "Content-Length", "Content-Type", and others. View quick reference t
#-*-Coding: UTF-8 -*-
# Python: 2.x
_ Author _ = 'admin'
Import cookielib
# Mainly used to process HTTP client cookies
# Cookielib. loaderror fails to be loaded in an exception file, which is a subclass of ioeerror.
# Cookielib. cookiejar is used to store Cookie objects. This module captures cookies and resends them when you are asking for further connection information. It can also be used to process files containing cookie data.
# Documentation: https://docs.python.org/2/library/cookielib.htm
real URL, which is useful because urlopen (or opener object) MayThere will be redirection. The obtained URL may be different from the requested URL.Info -- the dictionary object of the returned object, which describes the page information obtained. It is usually the specific headers sent by the server. Currently, this is an httplib. HTTPMessage instance.The classic headers include "Content-length", "Content-type", and others. View Quick Reference to
This change always refers to the browser window at the highest level of the split window. If you plan to execute the command from the highest level of the split window, you can use the top variable.
Parent:
This variable refers to the parent window that contains the current split window. If there is a split window in a window, and one of the split Windows contains a split window, the split window at the layer 2nd can be referenced with the parent variable to include its parent split window.
Cookies are data that the site stores on the user's local terminal in order to identify the user and perform session tracking (usually encrypted)Before that, you must first introduce the concept of a opener.
1.Opener
When you get a URL you use a opener (a urllib2. instance of Openerdirector).
Previously we were all using the default
Production"],"sum: Total production", subtotaltypes.sum); //set the style of a pivot table (Spire.xls supports more than 80 Excel built-in pivottable styles)Pivottable.builtinstyle =pivotbuiltinstyles.pivotstyledark13; //Save and open a documentWorkbook. SaveToFile ("pivot table. xlsx", excelversion.version2013); System.Diagnostics.Process.Start ("pivot table. xlsx");Test results:2. Set line collapse, expa
Golang Gin Practice Serial 14 implementing export, Import Excel
Original address: Gin practice serial 14 implementing export, Import ExcelProject Address: Https://github.com/EDDYCJY/go ...
If it helps, you're welcome to a Star.
Objective
In this section, we will implement the export of label information, import function, which is a standard feature, I hope you master the basic use of the way
In addition, in this article we used 2 Excel packages, excelize the original XML format file structure, i
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.