python 爬虫 爬取图片、mp3、小说

#首先调用requests库,使用requests.get('URL')获取文件,返回的是Response对象。
#然后需要把Response对象用合适的数据形式返回。
#存储数据:
#存储文件的三个步骤:打开文件,存储文件,关闭文件。.
import requests
sanguo = requests.get('https://localprod.pandateacher.com/python-manuscript/crawler- 
html/exercise/HTTP%E5%93%8D%E5%BA%94%E7%8A%B6%E6%80%81%E7%A0%81.md')
na = sanguo.text
k = open ('code.txt','w',encoding='utf-8')
k.write(na)
k.close()

#爬取图片
import requests
sanguo = requests.get('https://res.pandateacher.com/2019-01-12-15-29-33.png')
na = sanguo.content
k = open ('code.png','wb')
k.write(na)
k.close()

#爬取MP3
import requests
sanguo = requests.get('https://static.pandateacher.com/Over%20The%20Rainbow.mp3')
na = sanguo.content
k = open ('code.mp3','wb')
k.write(na)
k.close()

我来吐槽

*

*

仅有 1 条评论