字典传参
在百度上搜索简书,返回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)