日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python2與python3爬蟲中get與post對比

系統 2091 0
  1. python2中的urllib2改為python3中的urllib.request

  2. 四種方式對比:

python2的get:

          
            # coding=utf-8
import urllib
import urllib2

word = urllib.urlencode({"wd":"百度"})
url = 'http://www.baidu.com/s' + '?' + word
request = urllib2.Request(url)
print urllib2.urlopen(request).read().decode('utf-8')
          
        

python3的get

          
            import urllib.request
import urllib.parse

data = 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-8
import urllib
import urllib2

formdata = {
    '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.parse
import urllib.request

data = 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.parse
import urllib.request

request = 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'))
          
        

更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 桐柏县| 侯马市| 靖边县| 武汉市| 东宁县| 蛟河市| 仁寿县| 绿春县| 江川县| 溆浦县| 大安市| 叶城县| 广宁县| 友谊县| 洛扎县| 吉林省| 沅江市| 正宁县| 洪洞县| 江西省| 小金县| 安塞县| 海安县| 遂溪县| 泸西县| 晴隆县| 洛浦县| 宁蒗| 康保县| 涞水县| 藁城市| 沧州市| 洱源县| 元谋县| 沙洋县| 安图县| 手游| 霸州市| 保山市| 双辽市| 阿合奇县|