Introduction and usage of 'furl' category database in python
Introduction and usage of 'furl' category database in python
Overview:
FURL is a convenient and easy -to -use URL processing class library that can be used to analyze, build and operate the URL.It provides a simple way to handle each part of the URL and supports various common URL operations, such as adding, deleting and modifying query parameters, paths, etc.FURL also has the function of automatic encoding and decoding URL, which can handle special characters and encoding problems.
Instructions:
1. Install Furl Library: Run the `PIP Install Furl` in the command line to install the FURL class library.
2. Import FURL class library: Import the FURL class library in the Python script, and implement it through the `Import Furl` statement.
3. Create a FURL object: Create a URL object with the FRL class, you can pass the URL string or use the default constructor to create an empty URL object.For example:
python
url = furl.furl('http://example.com')
4. URL operation:
-Cap to get all parts of the URL: you can obtain various parts of the URL through the attributes of the object, such as `url.scheme` to obtain protocols,` url.host` to get the host name, `url.path` to get paths.For example:
python
Print (url.scheme) # Output: http
Print (url.host) # Output: example.com
-Codd each part of the URL: you can modify the various parts of the URL by assigning the attributes of the object, such as `url.scheme = 'https'` modify the protocol,` url.host =' newhost.com'` modify the host name, `Url.phpath = '/newpath'` modify the path, etc.For example:
python
url.scheme = 'https'
url.host = 'newhost.com'
url.path = '/newpath'
Print (url) # Output: https://newhost.com/newpath
-Adm and delete the query parameter: You can use the `ADD` method to add a query parameter, and use the` Remove` method to delete the specified query parameter.For example:
python
url.add (query_params = {'key': 'value'}) # Add query parameter
url.remove (ARGS = ['Key']) # Delete the specified query parameter
Print (url) # Output: https://newhost.com/newpath
5. Other common operations:
-Or automatically encoding and decoding: FURL can automatically encodes and decodes the URL to deal with special characters and coding problems.For example:
python
url = furl.furl('http://example.com/?query=hello%20world')
Print (url.query) # Output: query = Hello World
-Base URL: You can use the `Parse` method to resolve the URL string as FURL object.For example:
python
url = furl.parse('http://example.com/')
Print (url) # Output: http://example.com/
Summarize:
The FURL class library provides a simple and convenient way for the Python program.By creating a FURL object, you can easily analyze, build and operate the URL, including the sections of acquisition and modification of the URL, add and delete query parameters.In addition, FURL also has the functions of automatic encoding and decoding URL to deal with special characters and encoding problems.Using FURL can operate and deal with URL more efficiently to improve development efficiency.