Python gets the url content with the Chinese parameter through urllib2
- 2020-04-02 14:39:19
- OfStack
This article illustrates an example of how python gets url content with Chinese parameters through urllib2. Share with you for your reference. The details are as follows:
If the Chinese parameters are not encoded, the direct processing of python urllib2 will report an error. We can first convert the Chinese into utf-8 encoding, and then use the url encoding method urllib2.quote to pass the parameters.
content = u' hello jb51.net'
content = content.encode('utf-8')
content = urllib2.quote(content)
api_url = '//www.jb51.net/q=%s'%content
res = urllib2.urlopen(api_url)
I hope this article has helped you with your Python programming.