XPath (XML Path Language) Is a door in XML The language in which information is found in a document , Can be used in XML In the document, the elements and attributes are put into Traveled through .
XPath Use path expressions to select XML A node or set of nodes in a document . These path expressions are similar to what we see in a normal computer file system The expression to is very similar . The most common path expression ：
Predicate is used to find a specific node or a node containing a specified value , Embedded in square brackets .
XPath Wildcards can be used to select unknown XML Elements .
lxml yes One HTML/XML The parser , The main function is how to parse and extract HTML/XML data .
lxml Just like regular , Also use C Realized , It's a high-performance Python HTML/XML Parser , You can use what you learned before
XPath grammar , Quickly locate specific elements and node information .
lxml python Official documents :http://lxml.de/index.html
lxml It can be corrected automatically html Code , Not only did it complete li label , And added body,html label .
utilize etree.parse() Method to read the file
Now? API It's more and more , some “ mature ” The website will be constructed for themselves API For users or developers to use , For example, you can
Through Baidu map API Search the route , Positioning coordinates, etc . Through some music API Query singer information 、 Lyrics download, etc . By turning
translate API Real time translation of multiple languages . You can even pay a little bit to APIStorehttp://apistore.baidu.com/ Buy on API service ,
As shown in the figure .
API Generating data with a very standard set of rules , And the data generated is organized in a very standard way .
Because the rules are very standard , So something simple 、 The basic rules are easy to learn , You can quickly master API Usage of . But not
Not all API It's easy to use , There are some API The rules are many and complex , It is recommended that you carefully watch this before use API
Help document for .
Some simple API There is no need to validate the operation , But now most of them API It needs the user to submit verification .
The main purpose of submitting validation is to calculate API The cost of the call , This is common in paid API, For example, a weather check
Inquiry API, Turing's chat robot, etc , You need to buy to get apikey As validation, you can call API
Python There is an analysis in JSON A standard library of data , You can use it with the following code ：
Different from others Python The parsing library of ,JSON Parsing libraries is not about putting JSON The data is parsed as JSON Object or JSON node ,
But the JSON Data conversion to dictionary ,JSON Array to list ,JSON String conversion to Python character string . such ,
Then you can be relaxed about JSON The data is manipulated .