import requests # url = 'https://www.baidu.com' # response = requests.get(url) # print(response) # print(type(response)) # # 返回的页面是requests库猜测的编码方式,有误 # print(response.text) # content = response.content.decode('utf-8') # print(content) url = 'https://www.baidu.com/s' kw = {"wd": "猫"} headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" } response = requests.get(url, params=kw, headers=headers) # 打印requests库猜测的解码方式 print(response.encoding) content = response.content.decode('utf-8') print(content) # 查看状态码 print(response.status_code)