urlencode

urlencode将字符串以url的形式编码,返回值是一个字符串。例如空格在编码后会变成加号。

  • 在python3.6以后,通过from urllib.parse import urlencode导入,很久之前的版本,通过
    from urllib import urlencode的形式导入
python 例如:data = {
       'aid': 24,
       'offset' : offset,
       'format' : 'json',
       'keyword' : kw,
       'autoload' : 'true',
       'count' : 20,
       'cur_tab' : 1,
       'from' : 'search_tab',
       'pd' : 'synthesis'
   }
   ———( urlencode() )———>
  (以爬虫网址转换为例) 
  https://www.toutiao.com/api/search/content/?aid=24&offset=0&format=json&keyword=%E8%A1%97%E6%8B%8D&autoload=true&count=20&cur_tab=1&from=search_tab&pd=synthesis

猜你喜欢

转载自blog.csdn.net/dldl1718/article/details/87558229
今日推荐