python3的get

import urllib.requestimport urllib.parsedata = urllib.parse.urlencode({'wd':'百度'})url = 'http://wwww.baidu.com/s?' + data# url = 'http://www.baidu.com/s?wd=' + urllib.parse.quote('百度')response = urllib.request.urlopen(url)print (response.read().decode('utf-8'))

python2的post

# coding=utf-8import urllibimport urllib2formdata = {  'name':'百度'}data = urllib.urlencode(formdata)request = urllib2.Request(url = "http://httpbin.org/post", data=data)response = urllib2.urlopen(request)print response.read()

python3的post

import urllib.parseimport urllib.requestdata = bytes(urllib.parse.urlencode({'name':'百度'}),encoding='utf8')response = urllib.request.urlopen('http://httpbin.org/post',data=data)print(response.read().decode('utf-8'))

import urllib.parseimport urllib.requestrequest = urllib.request.Request('http://httpbin.org/post',data=bytes(urllib.parse.urlencode({'name':'百度'}),encoding='utf8))'))response = urllib.request.urlopen(request)print (response.read().decode('utf-8'))

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    python生成requirements.txt的两种方法
    下一条:
    python中class的定义及使用教程
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客