字典傳參
在百度上搜索簡(jiǎn)書绰筛,返回url為https://www.baidu.com/s?wd=簡(jiǎn)書
# -*- 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": "簡(jiǎn)書"}
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": "簡(jiǎn)書"}
js_url = "https://www.baidu.com/s?wd={}".format("簡(jiǎn)書")
response = requests.get(js_url, headers=headers, params=jianshu)
print(response.status_code)
print(response.request.url)