#! /usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from urllib.parse import urlencode
# 请求方式
kwords = input("请输入关键字:>>").strip()
res = urlencode({"wd":kwords}) # # 请求的url,当你在百度输入中文的时候,你把url拿下来会变成下面的这样格式的url,所以得urlencode一下
url ="
https://www.baidu.com/s?"+res #
https://www.baidu.com/s?wd=%E5%9B%BE%E7%89%87 response = requests.get(
# 请求的url,当你在百度输入中文的时候,你把url拿下来会变成下面的这样格式的url
url,
# 请求头
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/63.0.3239.108 Safari/537.36",
},
)
with open("a.html","w",encoding="utf-8") as f:
f.write(response.text)
print(response.status_code)