小爬虫学习.py 684 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: UTF-8 -*-
  2. import requests
  3. # url = 'https://doutula.com/photo/list/'
  4. url = "http://baidu.com"
  5. r = requests.get(url)
  6. # 获取 响应状态码
  7. print(r.status_code)
  8. # 拿到二进制的内容
  9. print(r.content)
  10. # 得到字符串的内容
  11. ## 方式1:
  12. # 我们自己指定一个字符编码进行解码
  13. print(r.content,enconding='utf-8')
  14. ## 方式2:
  15. # 使用系统默认的字符编码进行解码
  16. html = r.text
  17. print(html)
  18. #=======================爬取图片=========================#
  19. r = requests.get(url="http://img.doutula.com/production/uploads/image/2020/06/09/20200609705266_afoUFD.png")
  20. with open("./wangjingze.png", 'wb') as f:
  21. f.write(r.content)