Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the quote () method of python crawler

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report