Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the quote () method of python crawler

Shulou Source: shulou.com Published: 2022-06-03 17:35:40 11月13日 Update

Editor to share with you how to use the python crawler quote () method, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Description

1. Quote () can convert the content to URL-encoded format.

2. When there are Chinese parameters in URL, it may sometimes lead to garbled codes. At this point, Chinese characters can be converted to URL encoding in this way.

Example

From urllib.parse import quote keyword = 'wallpaper' url = 'https://www.baidu.com/s?wd=' + quote (keyword) print (url)

A Chinese search text is declared and then URL encoded with the quote () method.

Result

Https://www.baidu.com/s?wd=%E5%A3%81%E7%BA%B81https://www.baidu.com/s?wd=%E5%A3%81%E7%BA%B810. Unquote ()

With the quote () method and, of course, the unquote () method, which can be decoded for URL, the example is as follows:

From urllib.parse import unquote url = 'https://www.baidu.com/s?wd=%E5%A3%81%E7%BA%B8'print(unquote(url))

The URL-encoded result obtained above is restored here using the unquote () method.

The above https://www.baidu.com/s?wd= wallpaper is all the contents of this article entitled "how to use the python crawler quote () method". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Method coding content article crawler wallpaper result Chinese not much garbled parameters can be passed most characters examples text more Chinese format knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Redmi Docker Huawei