其他分享
首页 > 其他分享> > requests的get方法和参数格式

requests的get方法和参数格式

作者:互联网

get请求的格式

import requests

url = "https://tieba.baidu.com/f"
keyStr = "kw={}&ie=utf-8&pn={}".format("古风", 0)
headers = {
    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"}
response = requests.get(url, params =keyStr.format("古风".encode("utf-8"), 0),headers = headers )
# print(response)
# print(response.text)
# print(response.text)
# print(response.headers)
# print(response.request.headers)
# print(response.status_code)
# print(response.content)
# enStr = response.text.encode()
if response.status_code == 200 :
    filename = "古风贴吧第二页.html"
    with open(filename,"wb") as fd:

        fd.write(response.text.encode())
        

params的参数方式:

get中的参数:

标签:古风,get,headers,params,print,格式,requests,response
来源: https://www.cnblogs.com/zmdblog/p/12634989.html