基於python的-get和post請求

# -*- coding:utf-8 -*-

# import urllib
# import urllib2
# import urllib3
# import http

import requests

# 1. 使用requests發送get/post/put/delete等請求
# GET參數
# URL?參數1=內容1&參數2=內容2
# 注意:參數部分不能出現空格或者特殊字符
# response = requests.get("http://api.map.baidu.com/telematics/v3/weather?location=鄭州市&output=json&ak=TueGDhCvwI6fOrQnLM0qmXxY9N0OkOiQ&callback=?")
# print(response.content)

# 服務器向客戶端返回的數據格式有哪些?
# JSON/XML

# response = requests.get("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=93447709_hao_pg&wd=python")
# print(response.content)
#
# response = requests.get("https://www.baidu.com/s", params={"wd":"python"})
# print(response.content)

#-------------------------------------------------------------
# 參數1: url
# 參數2: data,類似於params
# 參數3: json
# 參數4: **kwargs
response = requests.post("http://dig.chouti.com/login",
                         data={
                             "phone":"8613203726750",
                             "password":"100xintong",
                            "onemonth":"1"
                         },
                         headers={
                             "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0"
                         }
                         )
# f = open("chouti.html","wb")
# f.write(response.content)
# f.close()
print(response.text)


# response = requests.put()
# response = requests.delete()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章