一、爬虫
二、Requests方法
1、requests.get()
import requests
res = requests.get('URL')
2、案例:用requests.get下载小说《三国演义》
import requests
res = requests.get('https://localprod.pandateacher.com/python-manuscript/crawler-html/sanguo.md')
novel=res.text
print(novel[:800])
3、Response对象常用属性
①、常见响应状态码
②、response.content
import requests
res = requests.get('https://res.pandateacher.com/2018-12-18-10-43-07.png')
pic=res.content
photo = open('ppt.jpg','wb')
photo.write(pic)
photo.close()
③、将小说保存到本地成txt
import requests
res = requests.get('https://localprod.pandateacher.com/python-manuscript/crawler-html/sanguo.md')
novel=res.text
k = open('《三国演义》.txt','a+')
k.write(novel)
k.close()
4、总结
三、爬虫伦理(Robots协议)
|