You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 anno fa
123456789101112131415161718192021222324
  1. import requests
  2. # url = 'https://www.baidu.com'
  3. # response = requests.get(url)
  4. # print(response)
  5. # print(type(response))
  6. # # 返回的页面是requests库猜测的编码方式,有误
  7. # print(response.text)
  8. # content = response.content.decode('utf-8')
  9. # print(content)
  10. url = 'https://www.baidu.com/s'
  11. kw = {"wd": "猫"}
  12. headers = {
  13. "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"
  14. }
  15. response = requests.get(url, params=kw, headers=headers)
  16. # 打印requests库猜测的解码方式
  17. print(response.encoding)
  18. content = response.content.decode('utf-8')
  19. print(content)
  20. # 查看状态码
  21. print(response.status_code)