登录
中文
cover

requests模块传递参数

字典传参

在百度上搜索简书,返回url为https://www.baidu.com/s?wd=简书

# -*- coding: utf-8 -*-
# @Time    : 2019/10/3 10:39
# @Author  : 币行者
# @Email   : xypip@qq.com
# @File    : test3.py

import requests

headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
jianshu = {"kw": "简书"}

js_url = "https://www.baidu.com/s?"

response = requests.get(js_url, headers=headers, params=jianshu)

print(response.status_code)
print(response.request.url)

format格式化

# -*- coding: utf-8 -*-
# @Time    : 2019/10/3 10:39
# @Author  : 币行者
# @Email   : xypip@qq.com
# @File    : test3.py

import requests

headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
jianshu = {"kw": "简书"}

js_url = "https://www.baidu.com/s?wd={}".format("简书")

response = requests.get(js_url, headers=headers, params=jianshu)

print(response.status_code)
print(response.request.url)

本文发布于瞬matataki, 请遵守协议许可进行转载

免责声明:本文由用户「币使者」上传发布,内容为作者独立观点。不代表瞬Matataki立场,不构成投资建议,请谨慎对待。

收藏
引用
分享
推荐
不推荐
0/500
1积分/条

评论 0

notContent

暂无内容