1 Star 0 Fork 0

周凌志/爬虫作业

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lesson13 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
周凌志 提交于 2021-12-03 05:29 . add lesson13.
import requests
from lxml import etree
url = 'http://www.sucaijishi.com/icon/'
res = requests.get(url)
res.encoding = res.apparent_encoding
#print(res.status_code)
#print(res.text)
ehtml = etree.HTML(res.text)
title = ehtml.xpath('//div[@class="w1180px common_list pt150"]//img/@src')
respic = requests.get(title[0])
print(respic.content)
pic = '测试图片.png'
with open(pic,'wb') as f:
f.write(respic.content)
#wz1 = ehtml.xpath('//p[@class="title ellipsis2"]/text()')
#print(wz1)
import request
from lxml import etree
url = 'https://www.ximalaya.com/yinyue/54070700/'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.0.8793 Safari/537.36'
}
res =res.get(url,headers=header)
print(res.status_code)
ehtml = etree.HTML(res.text)
title = ehtml.xpath('//div[@class="text Mi_"]/a/@href')
print(title)
for i in title:
id = i.split("/")[-1]
murl = 'https://www.ximalaya.com/revision/play/v1/audio?id' + id +'&ptype=1'
ires = request.get(murl,headers=header)
musicUrl = ires.json()['data']['src']
mres = request.get(musicUrl,headers=header)
filename = id + ".mp3"
with open(filename,'wb') as f:
f.write(mres.content)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou-lingzhi1218/crawler-operation.git
git@gitee.com:zhou-lingzhi1218/crawler-operation.git
zhou-lingzhi1218
crawler-operation
爬虫作业
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385