最近点赞了一些文章,觉得有些东西是我还没有接触过的,于是打算复刻一次,但是用我的思路,加上一些新的想法,最后我也是成功实现了这些功能。
私信小编01即可获取大量python学习资料
就和标题一样,这次打算解析一下 网易云 请求的参数,然后把爬来的歌曲编写到前端html代码里面,最后用代码实现QQ邮箱的发送功能,嗯,没错,确实创新了一点,但是在编写代码的框架思路上, 每个人都是有所不同, 找到自己的方法就可以了。
我本以为用python实现了它的加密算法之后,可以解析(very import person) 歌曲, 但是根据我的实际操作上,是不可以的,后面也会讲到,它们加密的参数是不一样的,都有各自的播放渠道, 如果你熟悉 html 你都可以发现他有二个播放渠道, 分别对应一般和特殊,所以后面我直接就开了黑胶会员, 我就想知道参数到底有什么不同, 不幸的是,当我在网页端登入账号的时候, 我发现在我打断点之后,我就不能启动调试功能了,相反的是 debugger parse 这样的字段,我尝试去解决这个问题,根据网上各种方式,到后面还是无济于事,索性放弃了,但是对于一般的 music , 是完全没有问题的,都可以下载,发送,保存到本地。
后面当我把这代码全部写好,加上了一些异常处理,我想到我的憨憨女友,索性再加一点代码实现,就把这些爬来的数据 写道一个 /<table> 里面, 然后在用其他函数库发送到她邮箱去了,单纯觉得好玩。
这篇文章有点长,因为有点难懂, 我只是想讲清楚一点,给她看,或者 给一些基础不是很好的人看一下, 大佬可以亲喷点,代码用到了很多库,但是我再后面也会一个个提到,不影响各位阅读, 只要耐心的看,你就一定有收获。
JS逆向, ASE加密, RES非对称算法,yagmail邮箱的发送,浏览器的debug,学到就是爽。
文章目录
- 前言:
- 效果图:
- 页面分析:
- 参数加密:
- 函数function A:
- 函数function B:
- 函数function C:
- 连贯加密函数类:
- ID获取:
- 获取免费单首ID:
- 获取id列表:
- 发送邮箱:
- 发送表格:
- 发送全部代码:
- 下载单曲代码:
- 关于__init__ :
效果图:
就是一个 html 表格, 熟悉的应该就直接能看出来, 然后还有img标签, a标签之类的。
页面分析:
当我们用chrome浏览器 (推荐用谷歌) 进入网易云官网,找到一首你喜欢的歌。
打开 f12 功能, 点击 XHR 过滤, 这个时候,我们点击播放, 在右侧就会重新捕获到新的网络请求,其中就包括我们需要的歌曲文件链接。就像这样。
v1?csrf … 这个网址就是刚刷的, 在响应中可以看到,有个url,你复制打开,就可以直接播放, 我们点击一下headers看看怎么发送的。
请求了request url , 用post发送, 下面有2个参数表单 params 和 encSecKey 貌似我们有下面2个参数就可以直接发送请求了, 所以直接就尝试了一下。
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">spider</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
<span style="color:#50a14f">"""
这是爬取一首歌的方式, 复制params就可以发送请求
"""</span>
r <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>post<span style="color:#999999">(</span>self<span style="color:#999999">.</span>params_url<span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>params<span style="color:#999999">)</span>
<span style="color:#0077aa">if</span> r<span style="color:#999999">.</span>status_code <span style="color:#a67f59">==</span> <span style="color:#986801">200</span><span style="color:#999999">:</span>
mp3 <span style="color:#a67f59">=</span> r<span style="color:#999999">.</span>json<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"data"</span><span style="color:#999999">)</span><span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"url"</span><span style="color:#999999">)</span>
rmp3 <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>get<span style="color:#999999">(</span>mp3<span style="color:#999999">,</span> headers<span style="color:#a67f59">=</span><span style="color:#999999">{</span><span style="color:#50a14f">"user-agent"</span><span style="color:#999999">:</span> self<span style="color:#999999">.</span>ua<span style="color:#999999">}</span><span style="color:#999999">)</span>
<span style="color:#0077aa">if</span> rmp3<span style="color:#999999">.</span>status_code <span style="color:#a67f59">==</span> <span style="color:#986801">200</span><span style="color:#999999">:</span>
<span style="color:#0077aa">with</span> <span style="color:#50a14f">open</span><span style="color:#999999">(</span><span style="color:#50a14f">"像鱼.mp3"</span><span style="color:#999999">,</span> <span style="color:#50a14f">'wb'</span><span style="color:#999999">)</span> <span style="color:#0077aa">as</span> fw<span style="color:#999999">:</span>
fw<span style="color:#999999">.</span>write<span style="color:#999999">(</span>rmp3<span style="color:#999999">.</span>content<span style="color:#999999">)</span>
<span style="color:#0077aa">print</span><span style="color:#999999">(</span><span style="color:#50a14f">"下载成功"</span><span style="color:#999999">)</span>
</code></span>
最后成功下载。
也就是说,我们只需要知道这二个参数怎么来的,就可以自己构造了,那就想怎么就怎么了,这个时候,我们就可以打开浏览器自带的调试功能了。要打断点,要debug, 怎么打,怎么断? 仔细点看我图的注释就可以了。
还是之前的包, 你点击第四个 initiator 就会刷新出很多和他有关系的文件, 我们点击第一个。
然后就来到这样, 还记得之前的二个参数吧, 在这里我们直接 ctrl + f 找其中的一个参数。
这里可以看到 params , encSecKey 都是根据 bvz7s 来的, 而bvz7s 是根据 window.asrsea() 函数来了, 所以在这个 函数打一个断点, 继续看下一个搜索点
在这里,我们发现window.asrsea = d 所以就得看 d 函数,在d函数的语气中,我们都可以打上断点,以便观察清楚。 打上断电之后, 刷新页面,等待一段时间。
之后就到第一个断点处, 然后 f8 跳到下一个断点
然后就可以发现 d 接受的4个参数是什么了, (d, e, f, g) 在右侧我们也可以看到,多次测试发现,后面三个是加密参数,固定值,所以复制拿过来用就可以了, 对于第一个d = {“csrf_token”:"…"} 这个是用来记录你是否登入账号, 如果你没有登陆, 那就是空。
继续f8 跳转到最后
发现就是把最开始接受的4个参数,然后经过a, b, b, c 函数处理就可以了,那待会我们就要看看每个函数有什么作用,这就涉及到他们的加密方式了,但是在这里,就要思考一个问题了,关于最开始的4个参数, 就一个d会变, 其他都没变化, 而且d还是一个空或者乱七八糟的的数字, 那他是怎么知道我是哪一首歌? 哪个歌手,所以这个参数一定有问题, (后面经过加密测试,发现加密后参数长度少了很多) 所以在这里我就继续 调试了一下, 一样的操作。
调试一圈了,最后终于有一个靠谱的了,有歌曲的id 还有歌曲的音质, 其他的,如果不熟悉,可以每一个d都去试试,直到加密参数正确。
所以先确定d为
"{"ids":"[1459950258]","level":"standard","encodeType":"aac","csrf_token":"59098e191e8babbaef83f1b8bbbe5987"}"
姑且就用这个d参数去加密尝试一次吧。
参数加密:
- 回到之前d函数的区域,就在d的上面,我们就可以看到a,b,c 函数的执行过程。
我们只需要一个个了解好,然后用python语言转换一下就可以了。下面分模块讲这些。
函数function A:
<span style="color:#000000"><code class="language-javascript"><span style="color:#0077aa">function</span> <span style="color:#dd4a68">a</span><span style="color:#999999">(</span>a<span style="color:#999999">)</span> <span style="color:#999999">{</span>
<span style="color:#0077aa">var</span> d<span style="color:#999999">,</span> e<span style="color:#999999">,</span> b <span style="color:#a67f59">=</span> <span style="color:#50a14f">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"</span><span style="color:#999999">,</span> c <span style="color:#a67f59">=</span> <span style="color:#50a14f">""</span><span style="color:#999999">;</span>
<span style="color:#0077aa">for</span> <span style="color:#999999">(</span>d <span style="color:#a67f59">=</span> <span style="color:#986801">0</span><span style="color:#999999">;</span> a <span style="color:#a67f59">></span> d<span style="color:#999999">;</span> d <span style="color:#a67f59">+=</span> <span style="color:#986801">1</span><span style="color:#999999">)</span>
e <span style="color:#a67f59">=</span> Math<span style="color:#999999">.</span><span style="color:#dd4a68">random</span><span style="color:#999999">(</span><span style="color:#999999">)</span> <span style="color:#a67f59">*</span> b<span style="color:#999999">.</span>length<span style="color:#999999">,</span>
e <span style="color:#a67f59">=</span> Math<span style="color:#999999">.</span><span style="color:#dd4a68">floor</span><span style="color:#999999">(</span>e<span style="color:#999999">)</span><span style="color:#999999">,</span>
c <span style="color:#a67f59">+=</span> b<span style="color:#999999">.</span><span style="color:#dd4a68">charAt</span><span style="color:#999999">(</span>e<span style="color:#999999">)</span><span style="color:#999999">;</span>
<span style="color:#0077aa">return</span> c
<span style="color:#999999">}</span>
</code></span>
熟悉的一看就知道, a函数接受一个a参数, 然后再一次循环中, 循环一次为a次, 然后从 b中 随机的挑选一些字符, 最后用字符串的形式返回, 对于Javascript来说,随机没那么容易,它需要用 random 生成 (0, 1) 的数,然后放大,取整,取值,累加,但对于python来说, 如下:
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">SimulateFunctionA</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> length<span style="color:#a67f59">=</span><span style="color:#0184bb">None</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
<span style="color:#50a14f">"""
@JavaScript
function a(a) {
var d, e, b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c = "";
for (d = 0; a > d; d += 1)
e = Ma() * b.length,
e = Ma(e),
c += b.charAt(e);
return c
}
length : 16
using the python get the c
"""</span>
b <span style="color:#a67f59">=</span> <span style="color:#50a14f">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'</span>
c <span style="color:#a67f59">=</span> random<span style="color:#999999">.</span>sample<span style="color:#999999">(</span>b<span style="color:#999999">,</span> length<span style="color:#999999">)</span>
<span style="color:#0077aa">return</span> <span style="color:#50a14f">""</span><span style="color:#999999">.</span>join<span style="color:#999999">(</span>c<span style="color:#999999">)</span>
</code></span>
简单.
函数function B:
<span style="color:#000000"><code class="language-javascript"> <span style="color:#0077aa">function</span> <span style="color:#dd4a68">b</span><span style="color:#999999">(</span>a<span style="color:#999999">,</span> b<span style="color:#999999">)</span> <span style="color:#999999">{</span>
<span style="color:#0077aa">var</span> c <span style="color:#a67f59">=</span> CryptoJS<span style="color:#999999">.</span>enc<span style="color:#999999">.</span>Utf8<span style="color:#999999">.</span><span style="color:#dd4a68">parse</span><span style="color:#999999">(</span>b<span style="color:#999999">)</span>
<span style="color:#999999">,</span> d <span style="color:#a67f59">=</span> CryptoJS<span style="color:#999999">.</span>enc<span style="color:#999999">.</span>Utf8<span style="color:#999999">.</span><span style="color:#dd4a68">parse</span><span style="color:#999999">(</span><span style="color:#50a14f">"0102030405060708"</span><span style="color:#999999">)</span>
<span style="color:#999999">,</span> e <span style="color:#a67f59">=</span> CryptoJS<span style="color:#999999">.</span>enc<span style="color:#999999">.</span>Utf8<span style="color:#999999">.</span><span style="color:#dd4a68">parse</span><span style="color:#999999">(</span>a<span style="color:#999999">)</span>
<span style="color:#999999">,</span> f <span style="color:#a67f59">=</span> CryptoJS<span style="color:#999999">.</span><span style="color:#986801">AES</span><span style="color:#999999">.</span><span style="color:#dd4a68">encrypt</span><span style="color:#999999">(</span>e<span style="color:#999999">,</span> c<span style="color:#999999">,</span> <span style="color:#999999">{</span>
iv<span style="color:#999999">:</span> d<span style="color:#999999">,</span>
mode<span style="color:#999999">:</span> CryptoJS<span style="color:#999999">.</span>mode<span style="color:#999999">.</span><span style="color:#986801">CBC</span>
<span style="color:#999999">}</span><span style="color:#999999">)</span><span style="color:#999999">;</span>
<span style="color:#0077aa">return</span> f<span style="color:#999999">.</span><span style="color:#dd4a68">toString</span><span style="color:#999999">(</span><span style="color:#999999">)</span>
<span style="color:#999999">}</span>
</code></span>
这是一个 AES 加密, 模式 CBC, 其实刚开始我也不知道AES加密是什么东西, 后面我查看了官网文档,参考了其他的办法,实现了。
官网文档
观察这个函数, 接受了a,b, 其中a,b 是什么可以在函数d中看到到。
根据之前的分析, g是固定值,我们已经复制下来, d 认为是一个字符字典
"{"ids":"[1459950258]","level":"standard","encodeType":"aac","csrf_token":"59098e191e8babbaef83f1b8bbbe5987"}"
这样,我们用python语言加入这些参数,试着模拟一下。
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">SimulateFunctionB</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> d<span style="color:#999999">,</span> key<span style="color:#999999">)</span><span style="color:#999999">:</span>
<span style="color:#50a14f">"""
function b(a, b) {
var c = Cry(b)
, d = Cry("0102030405060708")
, e = Cry(a)
, f = Cry(e, c, {
iv: d,
mode: Cry
});
return f.toString()
}
a = `"{"ids":"[1459950258]","level":"standard","encodeType":"aac","csrf_token":"59098e191e8babbaef83f1b8bbbe5987"}"`
b = key = (first) = SimulateFunctionA()(second)
"""</span>
key <span style="color:#a67f59">=</span> key<span style="color:#999999">.</span>encode<span style="color:#999999">(</span><span style="color:#999999">)</span>
iv <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>iv<span style="color:#999999">.</span>encode<span style="color:#999999">(</span><span style="color:#999999">)</span>
aes <span style="color:#a67f59">=</span> AES<span style="color:#999999">.</span>new<span style="color:#999999">(</span>key<span style="color:#a67f59">=</span>key<span style="color:#999999">,</span> mode<span style="color:#a67f59">=</span>AES<span style="color:#999999">.</span>MODE_CBC<span style="color:#999999">,</span> iv<span style="color:#a67f59">=</span>iv<span style="color:#999999">)</span>
text <span style="color:#a67f59">=</span> pad<span style="color:#999999">(</span>data_to_pad<span style="color:#a67f59">=</span>d<span style="color:#999999">.</span>encode<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">,</span> block_size<span style="color:#a67f59">=</span>AES<span style="color:#999999">.</span>block_size<span style="color:#999999">)</span>
aes_text <span style="color:#a67f59">=</span> aes<span style="color:#999999">.</span>encrypt<span style="color:#999999">(</span>plaintext<span style="color:#a67f59">=</span>text<span style="color:#999999">)</span>
aes_texts <span style="color:#a67f59">=</span> base64<span style="color:#999999">.</span>b64encode<span style="color:#999999">(</span>aes_text<span style="color:#999999">)</span><span style="color:#999999">.</span>decode<span style="color:#999999">(</span><span style="color:#999999">)</span>
<span style="color:#0077aa">return</span> aes_texts
SimulateFunticonB<span style="color:#999999">(</span>d<span style="color:#a67f59">=</span><span style="color:#50a14f">" `"</span><span style="color:#999999">{</span><span style="color:#50a14f">"ids"</span><span style="color:#999999">:</span><span style="color:#50a14f">"[1459950258]"</span><span style="color:#999999">,</span><span style="color:#50a14f">"level"</span><span style="color:#999999">:</span><span style="color:#50a14f">"standard"</span><span style="color:#999999">,</span><span style="color:#50a14f">"encodeType"</span><span style="color:#999999">:</span><span style="color:#50a14f">"aac"</span><span style="color:#999999">,</span><span style="color:#50a14f">"csrf_token"</span><span style="color:#999999">:</span><span style="color:#50a14f">"59098e191e8babbaef83f1b8bbbe5987"</span><span style="color:#999999">}</span><span style="color:#50a14f">"`"</span><span style="color:#999999">,</span> key<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>g<span style="color:#999999">)</span>
</code></span>
这里也是成功实现了,截图我忘记截了。
关于如何AES加密,可以直接看我的,有时间有兴趣的也可以和我一样看官网文档。 都行, 实现就可以了。函数function C:
<span style="color:#000000"><code class="language-javascript"> <span style="color:#0077aa">function</span> <span style="color:#dd4a68">c</span><span style="color:#999999">(</span>a<span style="color:#999999">,</span> b<span style="color:#999999">,</span> c<span style="color:#999999">)</span> <span style="color:#999999">{</span>
<span style="color:#0077aa">var</span> d<span style="color:#999999">,</span> e<span style="color:#999999">;</span>
<span style="color:#0077aa">return</span> <span style="color:#dd4a68">setMaxDigits</span><span style="color:#999999">(</span><span style="color:#986801">131</span><span style="color:#999999">)</span><span style="color:#999999">,</span>
d <span style="color:#a67f59">=</span> <span style="color:#0077aa">new</span> RSAKeyPair<span style="color:#999999">(</span>b<span style="color:#999999">,</span><span style="color:#50a14f">""</span><span style="color:#999999">,</span>c<span style="color:#999999">)</span><span style="color:#999999">,</span>
e <span style="color:#a67f59">=</span> <span style="color:#dd4a68">encryptedString</span><span style="color:#999999">(</span>d<span style="color:#999999">,</span> a<span style="color:#999999">)</span>
<span style="color:#999999">}</span>
</code></span>
一看很简单,其实复杂, 用到了RSA加密算法,关于RSA加密算法,我找了一些资料。
大致原理如图:
参考文档
我们用python这样实现;
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">SimulateFunctionC</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> random16<span style="color:#999999">)</span><span style="color:#999999">:</span>
<span style="color:#50a14f">"""
a = 131
RSA加密原理
# num = pow(x, y) % z
# 加密C=M^e mod n
"""</span>
e <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>e
f <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>f
text <span style="color:#a67f59">=</span> random16<span style="color:#999999">[</span><span style="color:#999999">:</span><span style="color:#999999">:</span><span style="color:#a67f59">-</span><span style="color:#986801">1</span><span style="color:#999999">]</span>
num <span style="color:#a67f59">=</span> <span style="color:#50a14f">pow</span><span style="color:#999999">(</span><span style="color:#50a14f">int</span><span style="color:#999999">(</span>text<span style="color:#999999">.</span>encode<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span><span style="color:#50a14f">hex</span><span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">,</span> <span style="color:#986801">16</span><span style="color:#999999">)</span><span style="color:#999999">,</span> <span style="color:#50a14f">int</span><span style="color:#999999">(</span>e<span style="color:#999999">,</span> <span style="color:#986801">16</span><span style="color:#999999">)</span><span style="color:#999999">,</span> <span style="color:#50a14f">int</span><span style="color:#999999">(</span>f<span style="color:#999999">,</span> <span style="color:#986801">16</span><span style="color:#999999">)</span><span style="color:#999999">)</span>
<span style="color:#0077aa">return</span> <span style="color:#50a14f">format</span><span style="color:#999999">(</span>num<span style="color:#999999">,</span> <span style="color:#50a14f">'x'</span><span style="color:#999999">)</span><span style="color:#999999">.</span>zfill<span style="color:#999999">(</span><span style="color:#986801">131</span><span style="color:#999999">)</span> <span style="color:#708090"># TODO: last the num change the hex digit and left fill (131)</span>
</code></span>
pow() 其实是可以接受三个参数的, 如果有第三个, 第三个就为取余值, 用上int(a, 16) 就可以直接将16进制转换为10进制, 最后的format(num, ‘x’) 将值用16进制形式输出, 然后zfill() 填充131 位数,, (根据函数C得知 位数为131)
连贯加密函数类:
分析了上面三个函数, 其实我们就可以直接编写程序加密了, 我们把程序连起来
- 说到底,我们还是要歌曲的id, 怎么来的,就需要继续看下去了。
ID获取:
获取免费单首ID:
直接这样就可以了。
获取id列表:
如果你是进入歌手表单在这个界面,你是找不到需要的id表单数据的,在这里就要用selenium 去爬取然后分析了,
如果你在下面的情况下,就可以找到id表单数据。
还有一样的,在这个包,我们看到参数还是params 和 encSerKey 然后重复上面操作, 打断点调试,甚至加密方式都是一样,不断的打断点,最后发现d是这样的
{"hlpretag":"<span class=\"s-fc7\">","hlposttag":"</span>","s":"许嵩","type":"1","offset":"0","total":"true","limit":"30","csrf_token":""}
我们更改一下s的值, 歌曲名称 歌手 都可以, 构建好这个字典, 发送这个网址,就可以得到id了, 然后拿着id去继续构造上面的d值, 就可以拿到歌曲url了。
发送邮箱:
- 函数库用到
- import keyring
- import yagmail
下载一下就可以了,
- 关于keyring 这是一个保存密码的库, 对于一些密码来说,我们可以这样
keyring set qq 88442764
然后就会让你输入密码 ,当你输入要获得就这样
keyring get qq 884427640 就可以了
前提你的keyring.exe 在环境变量中, 当然在python中,这个也是很简单使用的。 - 关于yagmail 这是一个发送邮箱的函数库
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">sent_email</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> content<span style="color:#999999">)</span><span style="color:#999999">:</span>
<span style="color:#50a14f">"""
sent the music demo list for you like one
"""</span>
pwd <span style="color:#a67f59">=</span> keyring<span style="color:#999999">.</span>get_password<span style="color:#999999">(</span><span style="color:#50a14f">"qqemail"</span><span style="color:#999999">,</span> <span style="color:#50a14f">"884427640"</span><span style="color:#999999">)</span>
yag <span style="color:#a67f59">=</span> yagmail<span style="color:#999999">.</span>SMTP<span style="color:#999999">(</span><span style="color:#50a14f">"884427640@qq.com"</span><span style="color:#999999">,</span> pwd<span style="color:#999999">,</span> host<span style="color:#a67f59">=</span><span style="color:#50a14f">";</span><span style="color:#999999">)</span>
<span style="color:#708090"># test qq 2817634007@qq.com</span>
yag<span style="color:#999999">.</span>send<span style="color:#999999">(</span>self<span style="color:#999999">.</span>Sented_qq_email<span style="color:#999999">,</span> <span style="color:#50a14f">'网易云专属推送'</span><span style="color:#999999">,</span> content<span style="color:#999999">)</span>
yag<span style="color:#999999">.</span>close<span style="color:#999999">(</span><span style="color:#999999">)</span>
<span style="color:#0077aa">print</span><span style="color:#999999">(</span><span style="color:#50a14f">"Today music already sent ok!"</span><span style="color:#999999">)</span>
</code></span>
pwd 这个是邮箱的QQ邮箱的授权码, 很长的字符串,要去QQ邮箱里面开启服务,所以我就放到密码库里面了,然后用SMTP链接一下邮箱, 就这样发送就可以了。
发送表格:
懂点html的都应该会编写这个。
<span style="color:#000000"><code class="language-python"> <span style="color:#0077aa">def</span> <span style="color:#dd4a68">random_get_mp3</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
mp3Ten <span style="color:#a67f59">=</span> random<span style="color:#999999">.</span>sample<span style="color:#999999">(</span>self<span style="color:#999999">.</span>MUSIC_LIST<span style="color:#999999">,</span> <span style="color:#986801">10</span><span style="color:#999999">)</span> <span style="color:#708090"># 提出十首歌</span>
content <span style="color:#a67f59">=</span> <span style="color:#50a14f">""</span> <span style="color:#708090"># 把数据写入html中 方便发送</span>
content <span style="color:#a67f59">+=</span> <span style="color:#50a14f">'<p><font size="20" color="Tan">Happy day for you !</font></p>'</span>
content <span style="color:#a67f59">+=</span> <span style="color:#50a14f">'<table border="1" style="border-collapse: collapse;">\n<caption>Today music demo </caption>\n<tr><th>序号</th><th>歌曲名</th><th>歌曲链接</th><th>歌曲所属</th><th>美图</th></tr>'</span>
count <span style="color:#a67f59">=</span> <span style="color:#986801">1</span>
<span style="color:#0077aa">for</span> j <span style="color:#0077aa">in</span> mp3Ten<span style="color:#999999">:</span>
s <span style="color:#a67f59">=</span> f<span style="color:#50a14f">"\n<tr><th>{count}</th><th>{j['singer_name']}</th>"</span> \
f<span style="color:#50a14f">"<th><a href='{et_mp3_url(j['id'])}'>点击播放</a></th><th>{j['album']}</th>"</span> \
f<span style="color:#50a14f">"<th><img src='{j['image']}' alt='美图' height='400' width='400' /></th></tr>"</span>
content <span style="color:#a67f59">+=</span> s
count <span style="color:#a67f59">+=</span> <span style="color:#986801">1</span>
content <span style="color:#a67f59">+=</span> <span style="color:#50a14f">"</table>"</span>
<span style="color:#0077aa">return</span> content
</code></span>
就这样写一下就可以了。
关于__init__ :
<span style="color:#000000"><code class="language-python"><span style="color:#50a14f">"""
如果你仅仅只是想下载一首歌 跳转到DownOneMp3模块启动模块运行
如果你想多首歌发送某人邮箱 跳转到DownMp3模块启动模块运行
"""</span>
</code></span>
JS逆向, ASE加密, RES非对称算法,yagmail邮箱的发送,浏览器的debug,学到就是爽。