登录
中文
cover

requests模块传递参数

本文内容已上传星际文件存储系统「IPFS」,永久保存,不可删除。

ipfs

字典传参

在百度上搜索简书,返回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

暂无内容