Rumah > Soal Jawab > teks badan
P粉2708916882023-08-24 11:41:36
Anda sedang mencari urllib.quote_plus
:
safe_string = urllib.quote_plus('string_of_characters_like_these:$#@=?%^Q^$') #Value: 'string_of_characters_like_these%3A%24%23%40%3D%3F%25%5EQ%5E%24'
Dalam Python 3, pakej urllib
telah dipecahkan kepada komponen yang lebih kecil. Anda akan menggunakan urllib.parse.quote_plus kod>
)urllib
包已被分解为更小的组件。您将使用 urllib.parse.quote_plus< /code>
(注意 parse
(perhatikan submodul
import urllib.parse safe_string = urllib.parse.quote_plus(...)
P粉5628459412023-08-24 00:39:26
Anda perlu menghantar parameter kepada urlencode()< /code>
sebagai peta (dikt) atau jujukan tupel, contohnya:
>>> import urllib >>> f = { 'eventName' : 'myEvent', 'eventDescription' : 'cool event'} >>> urllib.urlencode(f) 'eventName=myEvent&eventDescription=cool+event'
Python 3 atau lebih tinggi
Gunakan urllib.parse.urlencode< /代码>
:
>>> urllib.parse.urlencode(f) eventName=myEvent&eventDescription=cool+event
Perhatikan bahawa ini tidak melakukan pengekodan url dalam erti kata biasa (lihat output). Untuk melakukan ini, gunakan urllib.parse.quote_plus代码>
.