主頁 > 後端開發 > 教你學會網易云JS逆向,Python爬來的歌發女友郵箱可好?

教你學會網易云JS逆向,Python爬來的歌發女友郵箱可好?

2020-09-23 18:18:05 後端開發

最近點贊了一些文章,覺得有些東西是我還沒有接觸過的,于是打算復刻一次,但是用我的思路,加上一些新的想法,最后我也是成功實作了這些功能,

很多人學習python,不知道從何學起,
很多人學習python,掌握了基本語法過后,不知道在哪里尋找案例上手,
很多已經做案例的人,卻不知道如何去學習更加高深的知識,
那么針對這三類人,我給大家提供一個好的學習平臺,免費領取視頻教程,電子書籍,以及課程的源代碼!
QQ群:961562169



就和標題一樣,這次打算決議一下 網易云 請求的引數,然后把爬來的歌曲撰寫到前端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個引數就可以直接發送請求了, 所以直接就嘗試了一下,

    def spider(self):/n        /"/"/"/n        這是爬取一首歌的方式, 復制params就可以發送請求/n        /"/"/"/n        r = requests.post(self.params_url, params=self.params)/n        if r.status_code == 200:/n            mp3 = r.json().get(/"data/")[0].get(/"url/")/n            rmp3 = requests.get(mp3, headers={/"user-agent/": self.ua})/n            if rmp3.status_code == 200:/n                with open(/"像魚.mp3/", 'wb'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;as&lt;/span&gt; fw&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    fw&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;write&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;rmp3&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;下載成功\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code >    <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:

function a(a) {/n        var d, e, b = /"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/", c = /"/";/n        for (d = 0; a > d; d += 1)/n            e = Math.random() * b.length,/n            e = Math.floor(e),/n            c += b.charAt(e);/n        return c/n    }/n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><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來說, 如下:

 def SimulateFunctionA(self, length=None):/n        /"/"/"/n        @JavaScript/n         function a(a) {/n        var d, e, b = /"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/", c = /"/";/n        for (d = 0; a > d; d += 1)/n            e = Math.random() * b.length,/n            e = Math.floor(e),/n            c += b.charAt(e);/n        return c/n    }/n        length :  16/n        using the python get the c/n        /"/"/"/n        b = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'&lt;/span&gt;\n        c &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; random&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sample&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;b&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; length&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;join&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;c&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code > <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 = Math.random() * b.length,
            e = Math.floor(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:

 function b(a, b) {/n        var c = CryptoJS.enc.Utf8.parse(b)/n          , d = CryptoJS.enc.Utf8.parse(/"0102030405060708/")/n          , e = CryptoJS.enc.Utf8.parse(a)/n          , f = CryptoJS.AES.encrypt(e, c, {/n            iv: d,/n            mode: CryptoJS.mode.CBC/n        });/n        return f.toString()/n    }/n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code > <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語言加入這些引數,試著模擬一下,

 def SimulateFunctionB(self, d, key):/n        /"/"/"/n         function b(a, b) {/n        var c = CryptoJS.enc.Utf8.parse(b)/n          , d = CryptoJS.enc.Utf8.parse(/"0102030405060708/")/n          , e = CryptoJS.enc.Utf8.parse(a)/n          , f = CryptoJS.AES.encrypt(e, c, {/n            iv: d,/n            mode: CryptoJS.mode.CBC/n        });/n        return f.toString()/n    }/n    a =  `/"{/"ids/":/"[1459950258]/",/"level/":/"standard/",/"encodeType/":/"aac/",/"csrf_token/":/"59098e191e8babbaef83f1b8bbbe5987/"}/"`/n    b = key = self.g(first) = SimulateFunctionA()(second)/n        /"/"/"/n        key = key.encode()/n        iv = self.iv.encode()/n        aes = AES.new(key=key, mode=AES.MODE_CBC, iv=iv)/n        text = pad(data_to_pad=d.encode(), block_size=AES.block_size)/n        aes_text = aes.encrypt(plaintext=text)/n        aes_texts = base64.b64encode(aes_text).decode()/n        return aes_texts/n SimulateFunticonB(d=/" `/"{/"ids/":/"[1459950258]/",/"level/":/"standard/",/"encodeType/":/"aac/",/"csrf_token/":/"59098e191e8babbaef83f1b8bbbe5987/"}/"`/", key=self.g)/n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code > <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 = CryptoJS.enc.Utf8.parse(b)
          , d = CryptoJS.enc.Utf8.parse("0102030405060708")
          , e = CryptoJS.enc.Utf8.parse(a)
          , f = CryptoJS.AES.encrypt(e, c, {
            iv: d,
            mode: CryptoJS.mode.CBC
        });
        return f.toString()
    }
    a =  `"{"ids":"[1459950258]","level":"standard","encodeType":"aac","csrf_token":"59098e191e8babbaef83f1b8bbbe5987"}"`
    b = key = self.g(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:

    function c(a, b, c) {/n        var d, e;/n        return setMaxDigits(131),/n        d = new RSAKeyPair(b,/"/",c),/n        e = encryptedString(d, a)/n    }/n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code >    <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這樣實作;

    def SimulateFunctionC(self, random16):/n        /"/"/"/n        a = 131/n        RSA加密原理/n        # num = pow(x, y) % z/n        # 加密C=M^e mod n/n        /"/"/"/n        e = self.e/n        f = self.f/n        text = random16[::-1]/n        num = pow(int(text.encode().hex(), 16), int(e, 16), int(f, 16))/n        return format(num, 'x'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;zfill&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;131&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# TODO: last the num  change the hex  digit and left fill (131)&lt;/span&gt;\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code >    <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)

連貫加密函式類:

分析了上面三個函式, 其實我們就可以直接撰寫程式加密了, 我們把程式連起來,

# -*- coding :  utf-8 -*-/n# @Time      :  2020/9/15  15:45/n# @author    :  沙漏在下雨/n# @Software  :  PyCharm/n# @CSDN      :  https://me.csdn.net/qq_45906219/nimport requests/nfrom get_useragent import GetUserAgentCS/nimport random/nfrom Crypto.Util.Padding import pad/nfrom Crypto.Cipher import AES/nimport base64/n/n/nclass GetParams(object):/n    def __init__(self):/n        self.ua = GetUserAgentCS().get_user()/n        self.params_url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;e &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;010001\&quot;&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;g &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;0CoJUm6Qyw8W8jud\&quot;&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;iv &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'0102030405060708'&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;f &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a\&quot;&lt;/span&gt; \\\n                 &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9\&quot;&lt;/span&gt; \\\n                 &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e28\&quot;&lt;/span&gt; \\\n                 &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;9dc6935b3ece0462db0a22b8e7\&quot;&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;params &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;SimulateFunctionA&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; length&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        @JavaScript\n         function a(a) {\n        var d, e, b = \&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\&quot;, c = \&quot;\&quot;;\n        for (d = 0; a &gt; d; d += 1)\n            e = Math.random() * b.length,\n            e = Math.floor(e),\n            c += b.charAt(e);\n        return c\n    }\n        length :  16\n        using the python get the c\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        b &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'&lt;/span&gt;\n        c &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; random&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sample&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;b&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; length&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;join&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;c&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;SimulateFunctionB&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; d&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; key&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n         function b(a, b) {\n        var c = CryptoJS.enc.Utf8.parse(b)\n          , d = CryptoJS.enc.Utf8.parse(\&quot;0102030405060708\&quot;)\n          , e = CryptoJS.enc.Utf8.parse(a)\n          , f = CryptoJS.AES.encrypt(e, c, {\n            iv: d,\n            mode: CryptoJS.mode.CBC\n        });\n        return f.toString()\n    }\n    a = \&quot;{\&quot;csrf_token\&quot;:\&quot;\&quot;}\&quot;\n    b = key = self.g(first) = SimulateFunctionA()(second)\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        key &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; key&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        iv &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;iv&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        aes &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; AES&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;new&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;key&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;key&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; mode&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;AES&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MODE_CBC&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; iv&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;iv&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        text &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; pad&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;data_to_pad&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; block_size&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;AES&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;block_size&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        aes_text &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; aes&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encrypt&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;plaintext&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;text&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        aes_texts &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; base64&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;b64encode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;aes_text&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;decode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; aes_texts\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;SimulateFunctionC&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; random16&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        a = 131\n        RSA加密原理\n        # num = pow(x, y) % z\n        # 加密C=M^e mod n\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        e &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;e\n        f &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;f\n        text &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; random16&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;&lt;span style=\&quot;color:#a67f59\&quot;&gt;-&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n        num &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;pow&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;int&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;text&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encode&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;hex&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;16&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;int&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;e&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;16&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;int&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;f&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;16&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;format&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;num&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'x'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;zfill&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;131&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# TODO: last the num  change the hex  digit and left fill (131)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;spider&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        這是爬取一首歌的方式, 復制params就可以發送請求\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        r &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;post&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;params_url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            mp3 &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;json&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;data\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;url\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            rmp3 &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;mp3&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; headers&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;user-agent\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;ua&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; rmp3&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;with&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;open&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;像魚.mp3\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'wb'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;as&lt;/span&gt; fw&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    fw&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;write&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;rmp3&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;下載成功\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_encrypt_params&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; d&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        The function can encrypt your params if you give me a d\n        @params:  d   debug your chrome browser\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        i &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SimulateFunctionA&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;length&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;16&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        encText &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SimulateFunctionB&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;g&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        encText &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SimulateFunctionB&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;encText&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; i&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        encSecKey &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SimulateFunctionC&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;random16&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;i&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;params\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; encText&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;encSecKey\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; encSecKey\n        &lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a = GetParams()&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a.spider()&lt;/span&gt;\n\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><span style="color:#708090"># -*- coding :  utf-8 -*-</span>
<span style="color:#708090"># @Time      :  2020/9/15  15:45</span>
<span style="color:#708090"># @author    :  沙漏在下雨</span>
<span style="color:#708090"># @Software  :  PyCharm</span>
<span style="color:#708090"># @CSDN      :  https://me.csdn.net/qq_45906219</span>
<span style="color:#0077aa">import</span> requests
<span style="color:#0077aa">from</span> get_useragent <span style="color:#0077aa">import</span> GetUserAgentCS
<span style="color:#0077aa">import</span> random
<span style="color:#0077aa">from</span> Crypto<span style="color:#999999">.</span>Util<span style="color:#999999">.</span>Padding <span style="color:#0077aa">import</span> pad
<span style="color:#0077aa">from</span> Crypto<span style="color:#999999">.</span>Cipher <span style="color:#0077aa">import</span> AES
<span style="color:#0077aa">import</span> base64


<span style="color:#0077aa">class</span> GetParams<span style="color:#999999">(</span><span style="color:#50a14f">object</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">__init__</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        self<span style="color:#999999">.</span>ua <span style="color:#a67f59">=</span> GetUserAgentCS<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_user<span style="color:#999999">(</span><span style="color:#999999">)</span>
        self<span style="color:#999999">.</span>params_url <span style="color:#a67f59">=</span> <span style="color:#50a14f">'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='</span>
        self<span style="color:#999999">.</span>e <span style="color:#a67f59">=</span> <span style="color:#50a14f">"010001"</span>
        self<span style="color:#999999">.</span>g <span style="color:#a67f59">=</span> <span style="color:#50a14f">"0CoJUm6Qyw8W8jud"</span>
        self<span style="color:#999999">.</span>iv <span style="color:#a67f59">=</span> <span style="color:#50a14f">'0102030405060708'</span>
        self<span style="color:#999999">.</span>f <span style="color:#a67f59">=</span> <span style="color:#50a14f">"00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a"</span> \
                 <span style="color:#50a14f">"876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9"</span> \
                 <span style="color:#50a14f">"d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e28"</span> \
                 <span style="color:#50a14f">"9dc6935b3ece0462db0a22b8e7"</span>
        self<span style="color:#999999">.</span>params <span style="color:#a67f59">=</span> <span style="color:#0184bb">None</span>

    <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 = Math.random() * b.length,
            e = Math.floor(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>

    <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 = CryptoJS.enc.Utf8.parse(b)
          , d = CryptoJS.enc.Utf8.parse("0102030405060708")
          , e = CryptoJS.enc.Utf8.parse(a)
          , f = CryptoJS.AES.encrypt(e, c, {
            iv: d,
            mode: CryptoJS.mode.CBC
        });
        return f.toString()
    }
    a = "{"csrf_token":""}"
    b = key = self.g(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

    <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>

    <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>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_encrypt_params</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> d<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">"""
        The function can encrypt your params if you give me a d
        @params:  d   debug your chrome browser
        """</span>
        i <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>SimulateFunctionA<span style="color:#999999">(</span>length<span style="color:#a67f59">=</span><span style="color:#986801">16</span><span style="color:#999999">)</span>
        encText <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>SimulateFunctionB<span style="color:#999999">(</span>d<span style="color:#999999">,</span> self<span style="color:#999999">.</span>g<span style="color:#999999">)</span>
        encText <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>SimulateFunctionB<span style="color:#999999">(</span>encText<span style="color:#999999">,</span> i<span style="color:#999999">)</span>
        encSecKey <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>SimulateFunctionC<span style="color:#999999">(</span>random16<span style="color:#a67f59">=</span>i<span style="color:#999999">)</span>
        <span style="color:#0077aa">return</span> <span style="color:#999999">{</span>
            <span style="color:#50a14f">"params"</span><span style="color:#999999">:</span> encText<span style="color:#999999">,</span>
            <span style="color:#50a14f">"encSecKey"</span><span style="color:#999999">:</span> encSecKey
        <span style="color:#999999">}</span>

<span style="color:#708090"># a = GetParams()</span>
<span style="color:#708090"># a.spider()</span>

</code></span>
  • 說到底,我們還是要歌曲的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了,

如下:

# -*- coding :  utf-8 -*-/n# @Time      :  2020/9/17  14:59/n# @author    :  沙漏在下雨/n# @Software  :  PyCharm/n# @CSDN      :  https://me.csdn.net/qq_45906219/nfrom GetParams import GetParams/nimport requests/nfrom get_useragent import GetUserAgentCS/nimport random/nimport keyring/nimport yagmail/n/n/nclass DownMp3(object):/n    def __init__(self):/n        self.GetIdUrl = /"https://music.163.com/weapi/cloudsearch/get/web?csrf_token=\"\n        self.GetMP3Url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;ua &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetUserAgentCS&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_user&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;User-Agent\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;ua&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# The singer music demo list&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;Sented_qq_email &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_email&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_email&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        email_list &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;input&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;輸入QQ郵箱 如果你有多個 請用空格隔開:\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;split&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;len&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;email_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;@qq.com\&quot;&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;not&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;郵箱規格好像不合適,你輸入的是 \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;elif&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;len&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;email_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;2&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; i &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;@qq.com\&quot;&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;not&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; i&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;郵箱規格好像不合適,你輸入的是 \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; i&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    &lt;span style=\&quot;color:#0077aa\&quot;&gt;pass&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; email_list\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;my_request&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;get\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; model &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'post'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            r &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;post&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; headers&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encoding &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;apparent_encoding\n                s &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;json&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; s\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;elif&lt;/span&gt; model &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'get'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            r &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; headers&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;content\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;method is error !\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_mp3_id_demo&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; start&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        get the mp3 id\n        {\&quot;hlpretag\&quot;:\&quot;&lt;span class=\\\&quot;s-fc7\\\&quot;&gt;\&quot;,\&quot;hlposttag\&quot;:\&quot;&lt;/span&gt;\&quot;,\&quot;s\&quot;:\&quot;本兮\&quot;,\&quot;type\&quot;:\&quot;1\&quot;,\&quot;offset\&quot;:\&quot;0\&quot;,\&quot;total\&quot;:\&quot;true\&quot;,\&quot;limit\&quot;:\&quot;30\&quot;,\&quot;csrf_token\&quot;:\&quot;\&quot;}\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; start &lt;span style=\&quot;color:#0077aa\&quot;&gt;is&lt;/span&gt; &lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;You should enter a start name, but you enter start =\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; start&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        d &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;hlpretag\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;span class=\\\&quot;s-fc7\\\&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;hlposttag\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;/span&gt;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;s\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;start&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;type\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;1\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;offset\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;0\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;total\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;true\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;limit\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;30\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;csrf_token\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;\n        &lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        params &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetParams&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_encrypt_params&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;my_request&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;GetIdUrl&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;post\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;result\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;songs\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_mp3_url&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;id&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        params: id  the music of id\n        fix  the id into \&quot;{\&quot;ids\&quot;:\&quot;[35440198]\&quot;,\&quot;level\&quot;:\&quot;standard\&quot;,\&quot;encodeType\&quot;:\&quot;aac\&quot;,\&quot;csrf_token\&quot;:\&quot;\&quot;}\&quot;\n        so we can get the music the downpath\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        d &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;ids\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;id&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;level\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;standard\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;encodeType\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;aac\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;csrf_token\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        params &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetParams&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_encrypt_params&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        context &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;my_request&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;GetMP3Url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;post\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        mp3_path_url &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; context&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;data\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;url\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; mp3_path_url\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;print_id_list&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        params: id_list  print the singer about 30s  musics\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        a &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; index&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; value &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;enumerate&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;'count'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;index &lt;span style=\&quot;color:#a67f59\&quot;&gt;+&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;singer_name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;id\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;id\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;album\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;al\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;image\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;al\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;picUrl\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;append&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;a&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;copy&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;random_get_mp3&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        mp3Ten &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; random&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sample&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;10&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# 提出十首歌&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# 把資料寫入html中 方便發送&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'&lt;p&gt;&lt;font size=\&quot;20\&quot; color=\&quot;Tan\&quot;&gt;Happy day for you !&lt;/font&gt;&lt;/p&gt;'&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'&lt;table border=\&quot;1\&quot; style=\&quot;border-collapse: collapse;\&quot;&gt;\\n&lt;caption&gt;Today music demo &lt;/caption&gt;\\n&lt;tr&gt;&lt;th&gt;序號&lt;/th&gt;&lt;th&gt;歌曲名&lt;/th&gt;&lt;th&gt;歌曲鏈接&lt;/th&gt;&lt;th&gt;歌曲所屬&lt;/th&gt;&lt;th&gt;美圖&lt;/th&gt;&lt;/tr&gt;'&lt;/span&gt;\n        count &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; j &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; mp3Ten&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            s &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\\n&lt;tr&gt;&lt;th&gt;{count}&lt;/th&gt;&lt;th&gt;{j['singer_name']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;a href='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'&gt;點擊播放&lt;/a&gt;&lt;/th&gt;&lt;th&gt;{j['album']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;img src='https://www.cnblogs.com/41280a/p/{j['image']}'  alt='美圖' height='400' width='400' /&gt;&lt;/th&gt;&lt;/tr&gt;\&quot;&lt;/span&gt;\n            content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; s\n            count &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;/table&gt;\&quot;&lt;/span&gt;\n\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; content\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;sent_email&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        sent the music demo list for you like one\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        pwd &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; keyring&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_password&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;qqemail\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;884427640\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        yag &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; yagmail&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SMTP&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;[email protected]\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; pwd&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; host&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;smtp.qq.com\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#708090\&quot;&gt;# test qq [email protected]&lt;/span&gt;\n        yag&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;send&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;Sented_qq_email&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'網易云專屬推送'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        yag&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;close&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;Today music already sent ok!\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;start_demo&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;try&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            start_name &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;input&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;input a music singer or music name \&quot;&lt;/span&gt;\n                               &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;if  you like it:\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            id_list &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_mp3_id_demo&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;start&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;start_name&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;print_id_list&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sent_email&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;random_get_mp3&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;except&lt;/span&gt; Exception &lt;span style=\&quot;color:#0077aa\&quot;&gt;as&lt;/span&gt; e&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;出現error\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; e&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;再試一次!\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;start_demo&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n&lt;span style=\&quot;color:#708090\&quot;&gt;# 如果要運行此程式 請打開下面的注釋&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a = DownMp3()&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a.start_demo()&lt;/span&gt;\n\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><span style="color:#708090"># -*- coding :  utf-8 -*-</span>
<span style="color:#708090"># @Time      :  2020/9/17  14:59</span>
<span style="color:#708090"># @author    :  沙漏在下雨</span>
<span style="color:#708090"># @Software  :  PyCharm</span>
<span style="color:#708090"># @CSDN      :  https://me.csdn.net/qq_45906219</span>
<span style="color:#0077aa">from</span> GetParams <span style="color:#0077aa">import</span> GetParams
<span style="color:#0077aa">import</span> requests
<span style="color:#0077aa">from</span> get_useragent <span style="color:#0077aa">import</span> GetUserAgentCS
<span style="color:#0077aa">import</span> random
<span style="color:#0077aa">import</span> keyring
<span style="color:#0077aa">import</span> yagmail


<span style="color:#0077aa">class</span> DownMp3<span style="color:#999999">(</span><span style="color:#50a14f">object</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">__init__</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        self<span style="color:#999999">.</span>GetIdUrl <span style="color:#a67f59">=</span> <span style="color:#50a14f">"https://music.163.com/weapi/cloudsearch/get/web?csrf_token="</span>
        self<span style="color:#999999">.</span>GetMP3Url <span style="color:#a67f59">=</span> <span style="color:#50a14f">'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='</span>
        self<span style="color:#999999">.</span>ua <span style="color:#a67f59">=</span> GetUserAgentCS<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_user<span style="color:#999999">(</span><span style="color:#999999">)</span>
        self<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>
        self<span style="color:#999999">.</span>MUSIC_LIST <span style="color:#a67f59">=</span> <span style="color:#999999">[</span><span style="color:#999999">]</span>  <span style="color:#708090"># The singer music demo list</span>
        self<span style="color:#999999">.</span>Sented_qq_email <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_email<span style="color:#999999">(</span><span style="color:#999999">)</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_email</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        email_list <span style="color:#a67f59">=</span> <span style="color:#50a14f">input</span><span style="color:#999999">(</span><span style="color:#50a14f">"輸入QQ郵箱 如果你有多個 請用空格隔開:"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>split<span style="color:#999999">(</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">if</span> <span style="color:#50a14f">len</span><span style="color:#999999">(</span>email_list<span style="color:#999999">)</span> <span style="color:#a67f59">==</span> <span style="color:#986801">1</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">if</span> <span style="color:#50a14f">"@qq.com"</span> <span style="color:#a67f59">not</span> <span style="color:#0077aa">in</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span><span style="color:#999999">:</span>
                <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"郵箱規格好像不合適,你輸入的是 "</span><span style="color:#999999">,</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span><span style="color:#999999">)</span>
            <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
                <span style="color:#0077aa">return</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span>
        <span style="color:#0077aa">elif</span> <span style="color:#50a14f">len</span><span style="color:#999999">(</span>email_list<span style="color:#999999">)</span> <span style="color:#a67f59">>=</span> <span style="color:#986801">2</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">for</span> i <span style="color:#0077aa">in</span> email_list<span style="color:#999999">:</span>
                <span style="color:#0077aa">if</span> <span style="color:#50a14f">"@qq.com"</span> <span style="color:#a67f59">not</span> <span style="color:#0077aa">in</span> i<span style="color:#999999">:</span>
                    <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"郵箱規格好像不合適,你輸入的是 "</span><span style="color:#999999">,</span> i<span style="color:#999999">)</span>
                <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
                    <span style="color:#0077aa">pass</span>
            <span style="color:#0077aa">return</span> email_list

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">my_request</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> url<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"get"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span><span style="color:#0184bb">None</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#0077aa">if</span> model <span style="color:#a67f59">==</span> <span style="color:#50a14f">'post'</span><span style="color:#999999">:</span>
            r <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>post<span style="color:#999999">(</span>url<span style="color:#999999">,</span> headers<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>headers<span style="color:#999999">,</span> params<span style="color:#a67f59">=</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>
                r<span style="color:#999999">.</span>encoding <span style="color:#a67f59">=</span> r<span style="color:#999999">.</span>apparent_encoding
                s <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:#0077aa">return</span> s
        <span style="color:#0077aa">elif</span> model <span style="color:#a67f59">==</span> <span style="color:#50a14f">'get'</span><span style="color:#999999">:</span>
            r <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>get<span style="color:#999999">(</span>url<span style="color:#999999">,</span> headers<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>headers<span style="color:#999999">,</span> params<span style="color:#a67f59">=</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>
                <span style="color:#0077aa">return</span> r<span style="color:#999999">.</span>content
        <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"method is error !"</span><span style="color:#999999">)</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_mp3_id_demo</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> start<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">"""
        get the mp3 id
        {"hlpretag":"<span class=\"s-fc7\">","hlposttag":"</span>","s":"本兮","type":"1","offset":"0","total":"true","limit":"30","csrf_token":""}
        """</span>
        <span style="color:#0077aa">if</span> start <span style="color:#0077aa">is</span> <span style="color:#0184bb">None</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"You should enter a start name, but you enter start ="</span><span style="color:#999999">,</span> start<span style="color:#999999">)</span>
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span>
            <span style="color:#50a14f">"hlpretag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"<span class=\"s-fc7\">"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"hlposttag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"</span>"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"s"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span>start<span style="color:#999999">)</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"type"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"1"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"offset"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"0"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"total"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"true"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"limit"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"30"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"csrf_token"</span><span style="color:#999999">:</span> <span style="color:#50a14f">""</span>
        <span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">return</span> self<span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>self<span style="color:#999999">.</span>GetIdUrl<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"post"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>params<span style="color:#999999">)</span><span style="color:#999999">[</span><span style="color:#50a14f">"result"</span><span style="color:#999999">]</span><span style="color:#999999">[</span><span style="color:#50a14f">"songs"</span><span style="color:#999999">]</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_mp3_url</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> <span style="color:#50a14f">id</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""
        params: id  the music of id
        fix  the id into "{"ids":"[35440198]","level":"standard","encodeType":"aac","csrf_token":""}"
        so we can get the music the downpath
        """</span>
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span><span style="color:#50a14f">"ids"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span><span style="color:#999999">[</span><span style="color:#50a14f">id</span><span style="color:#999999">]</span><span style="color:#999999">)</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">""</span><span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        context <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>self<span style="color:#999999">.</span>GetMP3Url<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"post"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>params<span style="color:#999999">)</span>
        mp3_path_url <span style="color:#a67f59">=</span> context<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><span style="color:#50a14f">"url"</span><span style="color:#999999">]</span>

        <span style="color:#0077aa">return</span> mp3_path_url

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">print_id_list</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> id_list<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""
        params: id_list  print the singer about 30s  musics
        """</span>
        a <span style="color:#a67f59">=</span> <span style="color:#999999">{</span><span style="color:#999999">}</span>
        <span style="color:#0077aa">for</span> index<span style="color:#999999">,</span> value <span style="color:#0077aa">in</span> <span style="color:#50a14f">enumerate</span><span style="color:#999999">(</span>id_list<span style="color:#999999">)</span><span style="color:#999999">:</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">'count'</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> <span style="color:#999999">(</span>index <span style="color:#a67f59">+</span> <span style="color:#986801">1</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"singer_name"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"name"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"id"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"id"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"album"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"al"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"name"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"image"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"al"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"picUrl"</span><span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>MUSIC_LIST<span style="color:#999999">.</span>append<span style="color:#999999">(</span>a<span style="color:#999999">.</span>copy<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">)</span>

    <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='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'>點擊播放</a></th><th>{j['album']}</th>"</span> \
                f<span style="color:#50a14f">"<th><img src='https://www.cnblogs.com/41280a/p/{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

    <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">"[email protected]"</span><span style="color:#999999">,</span> pwd<span style="color:#999999">,</span> host<span style="color:#a67f59">=</span><span style="color:#50a14f">"smtp.qq.com"</span><span style="color:#999999">)</span>
        <span style="color:#708090"># test qq [email protected]</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>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">start_demo</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#0077aa">try</span><span style="color:#999999">:</span>
            start_name <span style="color:#a67f59">=</span> <span style="color:#50a14f">input</span><span style="color:#999999">(</span><span style="color:#50a14f">"input a music singer or music name "</span>
                               <span style="color:#50a14f">"if  you like it:"</span><span style="color:#999999">)</span>
            id_list <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_mp3_id_demo<span style="color:#999999">(</span>start<span style="color:#a67f59">=</span>start_name<span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>print_id_list<span style="color:#999999">(</span>id_list<span style="color:#999999">)</span>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span>self<span style="color:#999999">.</span>MUSIC_LIST<span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>sent_email<span style="color:#999999">(</span>self<span style="color:#999999">.</span>random_get_mp3<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">except</span> Exception <span style="color:#0077aa">as</span> e<span style="color:#999999">:</span>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span><span style="color:#50a14f">"出現error"</span><span style="color:#999999">,</span> e<span style="color:#999999">,</span> <span style="color:#50a14f">"再試一次!"</span><span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>start_demo<span style="color:#999999">(</span><span style="color:#999999">)</span>

<span style="color:#708090"># 如果要運行此程式 請打開下面的注釋</span>
<span style="color:#708090"># a = DownMp3()</span>
<span style="color:#708090"># a.start_demo()</span>

</code></span>

發送郵箱:

  • 函式庫用到
  • import keyring
  • import yagmail

下載一下就可以了,

  • 關于keyring 這是一個保存密碼的庫, 對于一些密碼來說,我們可以這樣
    keyring set qq 88442764
    然后就會讓你輸入密碼 ,當你輸入要獲得就這樣
    keyring get qq 884427640 就可以了
    前提你的keyring.exe 在環境變數中, 當然在python中,這個也是很簡單使用的,

  • 關于yagmail 這是一個發送郵箱的函式庫

 def sent_email(self, content):/n        /"/"/"/n        sent the music demo list for you like one/n        /"/"/"/n        pwd = keyring.get_password(/"qqemail/", /"884427640/")/n        yag = yagmail.SMTP(/"[email protected]/", pwd, host=/"smtp.qq.com/")/n        # test qq [email protected]/n        yag.send(self.Sented_qq_email, '網易云專屬推送'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        yag&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;close&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;Today music already sent ok!\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code > <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">"[email protected]"</span><span style="color:#999999">,</span> pwd<span style="color:#999999">,</span> host<span style="color:#a67f59">=</span><span style="color:#50a14f">"smtp.qq.com"</span><span style="color:#999999">)</span>
        <span style="color:#708090"># test qq [email protected]</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的都應該會撰寫這個,

    def random_get_mp3(self):/n        mp3Ten = random.sample(self.MUSIC_LIST, 10)  # 提出十首歌/n        content = /"/"  # 把資料寫入html中 方便發送/n        content += '&lt;p&gt;&lt;font size=\&quot;20\&quot; color=\&quot;Tan\&quot;&gt;Happy day for you !&lt;/font&gt;&lt;/p&gt;'&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'&lt;table border=\&quot;1\&quot; style=\&quot;border-collapse: collapse;\&quot;&gt;\\n&lt;caption&gt;Today music demo &lt;/caption&gt;\\n&lt;tr&gt;&lt;th&gt;序號&lt;/th&gt;&lt;th&gt;歌曲名&lt;/th&gt;&lt;th&gt;歌曲鏈接&lt;/th&gt;&lt;th&gt;歌曲所屬&lt;/th&gt;&lt;th&gt;美圖&lt;/th&gt;&lt;/tr&gt;'&lt;/span&gt;\n        count &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; j &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; mp3Ten&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            s &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\\n&lt;tr&gt;&lt;th&gt;{count}&lt;/th&gt;&lt;th&gt;{j['singer_name']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;a href='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'&gt;點擊播放&lt;/a&gt;&lt;/th&gt;&lt;th&gt;{j['album']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;img src='https://www.cnblogs.com/41280a/p/{j['image']}'  alt='美圖' height='400' width='400' /&gt;&lt;/th&gt;&lt;/tr&gt;\&quot;&lt;/span&gt;\n            content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; s\n            count &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;/table&gt;\&quot;&lt;/span&gt;\n\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; content\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code >    <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='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'>點擊播放</a></th><th>{j['album']}</th>"</span> \
                f<span style="color:#50a14f">"<th><img src='https://www.cnblogs.com/41280a/p/{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>

就這樣寫一下就可以了,

發送全部代碼:

# -*- coding :  utf-8 -*-/n# @Time      :  2020/9/17  14:59/n# @author    :  沙漏在下雨/n# @Software  :  PyCharm/n# @CSDN      :  https://me.csdn.net/qq_45906219/nfrom GetParams import GetParams/nimport requests/nfrom get_useragent import GetUserAgentCS/nimport random/nimport keyring/nimport yagmail/n/n/nclass DownMp3(object):/n    def __init__(self):/n        self.GetIdUrl = /"https://music.163.com/weapi/cloudsearch/get/web?csrf_token=\"\n        self.GetMP3Url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;ua &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetUserAgentCS&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_user&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;User-Agent\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;ua&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# The singer music demo list&lt;/span&gt;\n        self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;Sented_qq_email &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_email&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_email&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        email_list &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;input&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;輸入QQ郵箱 如果你有多個 請用空格隔開:\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;split&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;len&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;email_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;@qq.com\&quot;&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;not&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;郵箱規格好像不合適,你輸入的是 \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;elif&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;len&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;email_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;2&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; i &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; email_list&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;@qq.com\&quot;&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;not&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; i&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;郵箱規格好像不合適,你輸入的是 \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; i&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    &lt;span style=\&quot;color:#0077aa\&quot;&gt;pass&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; email_list\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;my_request&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;get\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; model &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'post'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            r &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;post&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; headers&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;encoding &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;apparent_encoding\n                s &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;json&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; s\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;elif&lt;/span&gt; model &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'get'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            r &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; requests&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; headers&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;headers&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;status_code &lt;span style=\&quot;color:#a67f59\&quot;&gt;==&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;200&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; r&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;content\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;else&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;method is error !\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_mp3_id_demo&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; start&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        get the mp3 id\n        {\&quot;hlpretag\&quot;:\&quot;&lt;span class=\\\&quot;s-fc7\\\&quot;&gt;\&quot;,\&quot;hlposttag\&quot;:\&quot;&lt;/span&gt;\&quot;,\&quot;s\&quot;:\&quot;本兮\&quot;,\&quot;type\&quot;:\&quot;1\&quot;,\&quot;offset\&quot;:\&quot;0\&quot;,\&quot;total\&quot;:\&quot;true\&quot;,\&quot;limit\&quot;:\&quot;30\&quot;,\&quot;csrf_token\&quot;:\&quot;\&quot;}\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;if&lt;/span&gt; start &lt;span style=\&quot;color:#0077aa\&quot;&gt;is&lt;/span&gt; &lt;span style=\&quot;color:#0184bb\&quot;&gt;None&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;raise&lt;/span&gt; Exception&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;You should enter a start name, but you enter start =\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; start&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        d &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;hlpretag\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;span class=\\\&quot;s-fc7\\\&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;hlposttag\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;/span&gt;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;s\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;start&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;type\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;1\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;offset\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;0\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;total\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;true\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;limit\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;30\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt;\n            &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;csrf_token\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;\n        &lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        params &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetParams&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_encrypt_params&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;my_request&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;GetIdUrl&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;post\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;result\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;songs\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;get_mp3_url&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;id&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        params: id  the music of id\n        fix  the id into \&quot;{\&quot;ids\&quot;:\&quot;[35440198]\&quot;,\&quot;level\&quot;:\&quot;standard\&quot;,\&quot;encodeType\&quot;:\&quot;aac\&quot;,\&quot;csrf_token\&quot;:\&quot;\&quot;}\&quot;\n        so we can get the music the downpath\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        d &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;ids\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;id&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;level\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;standard\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;encodeType\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;aac\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;csrf_token\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        params &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; GetParams&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_encrypt_params&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;str&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;d&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        context &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;my_request&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;GetMP3Url&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; model&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;post\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; params&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;params&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        mp3_path_url &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; context&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;data\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#986801\&quot;&gt;0&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;url\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt;\n\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; mp3_path_url\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;print_id_list&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        params: id_list  print the singer about 30s  musics\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        a &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;{&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;}&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; index&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; value &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;enumerate&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;'count'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;index &lt;span style=\&quot;color:#a67f59\&quot;&gt;+&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;singer_name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;id\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;id\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;album\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;al\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;name\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            a&lt;span style=\&quot;color:#999999\&quot;&gt;[&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;image\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;]&lt;/span&gt; &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; value&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;al\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;picUrl\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;append&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;a&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;copy&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;random_get_mp3&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        mp3Ten &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; random&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sample&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;10&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# 提出十首歌&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;&lt;/span&gt;  &lt;span style=\&quot;color:#708090\&quot;&gt;# 把資料寫入html中 方便發送&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'&lt;p&gt;&lt;font size=\&quot;20\&quot; color=\&quot;Tan\&quot;&gt;Happy day for you !&lt;/font&gt;&lt;/p&gt;'&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'&lt;table border=\&quot;1\&quot; style=\&quot;border-collapse: collapse;\&quot;&gt;\\n&lt;caption&gt;Today music demo &lt;/caption&gt;\\n&lt;tr&gt;&lt;th&gt;序號&lt;/th&gt;&lt;th&gt;歌曲名&lt;/th&gt;&lt;th&gt;歌曲鏈接&lt;/th&gt;&lt;th&gt;歌曲所屬&lt;/th&gt;&lt;th&gt;美圖&lt;/th&gt;&lt;/tr&gt;'&lt;/span&gt;\n        count &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;for&lt;/span&gt; j &lt;span style=\&quot;color:#0077aa\&quot;&gt;in&lt;/span&gt; mp3Ten&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            s &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\\n&lt;tr&gt;&lt;th&gt;{count}&lt;/th&gt;&lt;th&gt;{j['singer_name']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;a href='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'&gt;點擊播放&lt;/a&gt;&lt;/th&gt;&lt;th&gt;{j['album']}&lt;/th&gt;\&quot;&lt;/span&gt; \\\n                f&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;th&gt;&lt;img src='https://www.cnblogs.com/41280a/p/{j['image']}'  alt='美圖' height='400' width='400' /&gt;&lt;/th&gt;&lt;/tr&gt;\&quot;&lt;/span&gt;\n            content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; s\n            count &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#986801\&quot;&gt;1&lt;/span&gt;\n        content &lt;span style=\&quot;color:#a67f59\&quot;&gt;+=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;&lt;/table&gt;\&quot;&lt;/span&gt;\n\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;return&lt;/span&gt; content\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;sent_email&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;\&quot;\&quot;\n        sent the music demo list for you like one\n        \&quot;\&quot;\&quot;&lt;/span&gt;\n        pwd &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; keyring&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_password&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;qqemail\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;884427640\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        yag &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; yagmail&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;SMTP&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;[email protected]\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; pwd&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; host&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;smtp.qq.com\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#708090\&quot;&gt;# test qq [email protected]&lt;/span&gt;\n        yag&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;send&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;Sented_qq_email&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;'網易云專屬推送'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        yag&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;close&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;Today music already sent ok!\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n    &lt;span style=\&quot;color:#0077aa\&quot;&gt;def&lt;/span&gt; &lt;span style=\&quot;color:#dd4a68\&quot;&gt;start_demo&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;try&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            start_name &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;input&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;input a music singer or music name \&quot;&lt;/span&gt;\n                               &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;if  you like it:\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            id_list &lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt; self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;get_mp3_id_demo&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;start&lt;span style=\&quot;color:#a67f59\&quot;&gt;=&lt;/span&gt;start_name&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;print_id_list&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;id_list&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;MUSIC_LIST&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;sent_email&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;random_get_mp3&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n        &lt;span style=\&quot;color:#0077aa\&quot;&gt;except&lt;/span&gt; Exception &lt;span style=\&quot;color:#0077aa\&quot;&gt;as&lt;/span&gt; e&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n            &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;出現error\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; e&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;再試一次!\&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n            self&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;start_demo&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n&lt;span style=\&quot;color:#708090\&quot;&gt;# 如果要運行此程式 請打開下面的注釋&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a = DownMp3()&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a.start_demo()&lt;/span&gt;\n\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><span style="color:#708090"># -*- coding :  utf-8 -*-</span>
<span style="color:#708090"># @Time      :  2020/9/17  14:59</span>
<span style="color:#708090"># @author    :  沙漏在下雨</span>
<span style="color:#708090"># @Software  :  PyCharm</span>
<span style="color:#708090"># @CSDN      :  https://me.csdn.net/qq_45906219</span>
<span style="color:#0077aa">from</span> GetParams <span style="color:#0077aa">import</span> GetParams
<span style="color:#0077aa">import</span> requests
<span style="color:#0077aa">from</span> get_useragent <span style="color:#0077aa">import</span> GetUserAgentCS
<span style="color:#0077aa">import</span> random
<span style="color:#0077aa">import</span> keyring
<span style="color:#0077aa">import</span> yagmail


<span style="color:#0077aa">class</span> DownMp3<span style="color:#999999">(</span><span style="color:#50a14f">object</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">__init__</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        self<span style="color:#999999">.</span>GetIdUrl <span style="color:#a67f59">=</span> <span style="color:#50a14f">"https://music.163.com/weapi/cloudsearch/get/web?csrf_token="</span>
        self<span style="color:#999999">.</span>GetMP3Url <span style="color:#a67f59">=</span> <span style="color:#50a14f">'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='</span>
        self<span style="color:#999999">.</span>ua <span style="color:#a67f59">=</span> GetUserAgentCS<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_user<span style="color:#999999">(</span><span style="color:#999999">)</span>
        self<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>
        self<span style="color:#999999">.</span>MUSIC_LIST <span style="color:#a67f59">=</span> <span style="color:#999999">[</span><span style="color:#999999">]</span>  <span style="color:#708090"># The singer music demo list</span>
        self<span style="color:#999999">.</span>Sented_qq_email <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_email<span style="color:#999999">(</span><span style="color:#999999">)</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_email</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        email_list <span style="color:#a67f59">=</span> <span style="color:#50a14f">input</span><span style="color:#999999">(</span><span style="color:#50a14f">"輸入QQ郵箱 如果你有多個 請用空格隔開:"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>split<span style="color:#999999">(</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">if</span> <span style="color:#50a14f">len</span><span style="color:#999999">(</span>email_list<span style="color:#999999">)</span> <span style="color:#a67f59">==</span> <span style="color:#986801">1</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">if</span> <span style="color:#50a14f">"@qq.com"</span> <span style="color:#a67f59">not</span> <span style="color:#0077aa">in</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span><span style="color:#999999">:</span>
                <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"郵箱規格好像不合適,你輸入的是 "</span><span style="color:#999999">,</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span><span style="color:#999999">)</span>
            <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
                <span style="color:#0077aa">return</span> email_list<span style="color:#999999">[</span><span style="color:#986801">0</span><span style="color:#999999">]</span>
        <span style="color:#0077aa">elif</span> <span style="color:#50a14f">len</span><span style="color:#999999">(</span>email_list<span style="color:#999999">)</span> <span style="color:#a67f59">>=</span> <span style="color:#986801">2</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">for</span> i <span style="color:#0077aa">in</span> email_list<span style="color:#999999">:</span>
                <span style="color:#0077aa">if</span> <span style="color:#50a14f">"@qq.com"</span> <span style="color:#a67f59">not</span> <span style="color:#0077aa">in</span> i<span style="color:#999999">:</span>
                    <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"郵箱規格好像不合適,你輸入的是 "</span><span style="color:#999999">,</span> i<span style="color:#999999">)</span>
                <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
                    <span style="color:#0077aa">pass</span>
            <span style="color:#0077aa">return</span> email_list

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">my_request</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> url<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"get"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span><span style="color:#0184bb">None</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#0077aa">if</span> model <span style="color:#a67f59">==</span> <span style="color:#50a14f">'post'</span><span style="color:#999999">:</span>
            r <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>post<span style="color:#999999">(</span>url<span style="color:#999999">,</span> headers<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>headers<span style="color:#999999">,</span> params<span style="color:#a67f59">=</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>
                r<span style="color:#999999">.</span>encoding <span style="color:#a67f59">=</span> r<span style="color:#999999">.</span>apparent_encoding
                s <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:#0077aa">return</span> s
        <span style="color:#0077aa">elif</span> model <span style="color:#a67f59">==</span> <span style="color:#50a14f">'get'</span><span style="color:#999999">:</span>
            r <span style="color:#a67f59">=</span> requests<span style="color:#999999">.</span>get<span style="color:#999999">(</span>url<span style="color:#999999">,</span> headers<span style="color:#a67f59">=</span>self<span style="color:#999999">.</span>headers<span style="color:#999999">,</span> params<span style="color:#a67f59">=</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>
                <span style="color:#0077aa">return</span> r<span style="color:#999999">.</span>content
        <span style="color:#0077aa">else</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"method is error !"</span><span style="color:#999999">)</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_mp3_id_demo</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> start<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">"""
        get the mp3 id
        {"hlpretag":"<span class=\"s-fc7\">","hlposttag":"</span>","s":"本兮","type":"1","offset":"0","total":"true","limit":"30","csrf_token":""}
        """</span>
        <span style="color:#0077aa">if</span> start <span style="color:#0077aa">is</span> <span style="color:#0184bb">None</span><span style="color:#999999">:</span>
            <span style="color:#0077aa">raise</span> Exception<span style="color:#999999">(</span><span style="color:#50a14f">"You should enter a start name, but you enter start ="</span><span style="color:#999999">,</span> start<span style="color:#999999">)</span>
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span>
            <span style="color:#50a14f">"hlpretag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"<span class=\"s-fc7\">"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"hlposttag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"</span>"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"s"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span>start<span style="color:#999999">)</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"type"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"1"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"offset"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"0"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"total"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"true"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"limit"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"30"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"csrf_token"</span><span style="color:#999999">:</span> <span style="color:#50a14f">""</span>
        <span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">return</span> self<span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>self<span style="color:#999999">.</span>GetIdUrl<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"post"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>params<span style="color:#999999">)</span><span style="color:#999999">[</span><span style="color:#50a14f">"result"</span><span style="color:#999999">]</span><span style="color:#999999">[</span><span style="color:#50a14f">"songs"</span><span style="color:#999999">]</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_mp3_url</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> <span style="color:#50a14f">id</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""
        params: id  the music of id
        fix  the id into "{"ids":"[35440198]","level":"standard","encodeType":"aac","csrf_token":""}"
        so we can get the music the downpath
        """</span>
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span><span style="color:#50a14f">"ids"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span><span style="color:#999999">[</span><span style="color:#50a14f">id</span><span style="color:#999999">]</span><span style="color:#999999">)</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">""</span><span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        context <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>self<span style="color:#999999">.</span>GetMP3Url<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"post"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>params<span style="color:#999999">)</span>
        mp3_path_url <span style="color:#a67f59">=</span> context<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><span style="color:#50a14f">"url"</span><span style="color:#999999">]</span>

        <span style="color:#0077aa">return</span> mp3_path_url

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">print_id_list</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> id_list<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""
        params: id_list  print the singer about 30s  musics
        """</span>
        a <span style="color:#a67f59">=</span> <span style="color:#999999">{</span><span style="color:#999999">}</span>
        <span style="color:#0077aa">for</span> index<span style="color:#999999">,</span> value <span style="color:#0077aa">in</span> <span style="color:#50a14f">enumerate</span><span style="color:#999999">(</span>id_list<span style="color:#999999">)</span><span style="color:#999999">:</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">'count'</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> <span style="color:#999999">(</span>index <span style="color:#a67f59">+</span> <span style="color:#986801">1</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"singer_name"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"name"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"id"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"id"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"album"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"al"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"name"</span><span style="color:#999999">)</span>
            a<span style="color:#999999">[</span><span style="color:#50a14f">"image"</span><span style="color:#999999">]</span> <span style="color:#a67f59">=</span> value<span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"al"</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get<span style="color:#999999">(</span><span style="color:#50a14f">"picUrl"</span><span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>MUSIC_LIST<span style="color:#999999">.</span>append<span style="color:#999999">(</span>a<span style="color:#999999">.</span>copy<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">)</span>

    <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='https://www.cnblogs.com/41280a/p/{self.get_mp3_url(j['id'])}'>點擊播放</a></th><th>{j['album']}</th>"</span> \
                f<span style="color:#50a14f">"<th><img src='https://www.cnblogs.com/41280a/p/{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

    <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">"[email protected]"</span><span style="color:#999999">,</span> pwd<span style="color:#999999">,</span> host<span style="color:#a67f59">=</span><span style="color:#50a14f">"smtp.qq.com"</span><span style="color:#999999">)</span>
        <span style="color:#708090"># test qq [email protected]</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>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">start_demo</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#0077aa">try</span><span style="color:#999999">:</span>
            start_name <span style="color:#a67f59">=</span> <span style="color:#50a14f">input</span><span style="color:#999999">(</span><span style="color:#50a14f">"input a music singer or music name "</span>
                               <span style="color:#50a14f">"if  you like it:"</span><span style="color:#999999">)</span>
            id_list <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_mp3_id_demo<span style="color:#999999">(</span>start<span style="color:#a67f59">=</span>start_name<span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>print_id_list<span style="color:#999999">(</span>id_list<span style="color:#999999">)</span>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span>self<span style="color:#999999">.</span>MUSIC_LIST<span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>sent_email<span style="color:#999999">(</span>self<span style="color:#999999">.</span>random_get_mp3<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">except</span> Exception <span style="color:#0077aa">as</span> e<span style="color:#999999">:</span>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span><span style="color:#50a14f">"出現error"</span><span style="color:#999999">,</span> e<span style="color:#999999">,</span> <span style="color:#50a14f">"再試一次!"</span><span style="color:#999999">)</span>
            self<span style="color:#999999">.</span>start_demo<span style="color:#999999">(</span><span style="color:#999999">)</span>

<span style="color:#708090"># 如果要運行此程式 請打開下面的注釋</span>
<span style="color:#708090"># a = DownMp3()</span>
<span style="color:#708090"># a.start_demo()</span>

</code></span>

下載單曲代碼:

擴展了一個下載一首歌的代碼,如果你需要,

# -*- coding :  utf-8 -*-/n# @Time      :  2020/9/17  21:35/n# @author    :  沙漏在下雨/n# @Software  :  PyCharm/n# @CSDN      :  https://me.csdn.net/qq_45906219/nimport requests/nfrom get_useragent import GetUserAgentCS/nfrom GetParams import GetParams/nfrom DownMp3 import DownMp3/n/n/nclass DownOneMp3(DownMp3):/n    def __init__(self):/n        super().__init__()/n        self.GetIdUrl = /"https://music.163.com/weapi/cloudsearch/get/web?csrf_token=\"\n        self.params_url = \"https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=\"\n        self.headers = {\"user-agent\": GetUserAgentCS().get_user()}\n        self.start = input(\"Please input the music name:\")\n        ids = self.get_id()\n        self.params = self.get_params(id=ids)\n        self.mp3_name = self.start + \".mp3\"\n\n    def my_request(self, url, model=\"get\", params=None):\n        \"\"\"\n        繼承父類的一個方法\n        \"\"\"\n        return super().my_request(url, model, params)\n\n    def get_params(self, id):\n        \"\"\"給出id 回傳加密引數\"\"\"\n        d = {\"ids\": str([id]), \"level\": \"standard\", \"encodeType\": \"aac\", \"csrf_token\": \"\"}\n        params = GetParams().get_encrypt_params(str(d))\n        return params\n\n    def get_id(self):\n        \"\"\"\n        根據歌曲名稱獲取id\n        \"\"\"\n        start = self.start\n        d = {\n            \"hlpretag\": \"\",\n            \"hlposttag\": \"\",\n            \"s\": str(start),\n            \"type\": \"1\",\n            \"offset\": \"0\",\n            \"total\": \"true\",\n            \"limit\": \"30\",\n            \"csrf_token\": \"\"\n        }\n        params = GetParams().get_encrypt_params(str(d))\n        return self.my_request(self.GetIdUrl, model=\"post\", params=params)[\"result\"][\"songs\"][0].get(\"id\")\n\n    def spider(self):\n        \"\"\"\n        這是爬取一首歌的方式, 你只需要輸入歌曲名稱就可以 會自動呼叫其他類實作引數加密 id獲取等\n        \"\"\"\n\n        import os\n        r = requests.post(self.params_url, params=self.params)\n        if r.status_code == 200:\n            print(r.json())\n            mp3 = r.json().get(\"data\")[0].get(\"url\")\n            print(\"music link is \", mp3)\n            rmp3 = requests.get(mp3, headers=self.headers)\n            if rmp3.status_code == 200:\n                with open(self.mp3_name, 'wb'&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt; &lt;span style=\&quot;color:#0077aa\&quot;&gt;as&lt;/span&gt; fw&lt;span style=\&quot;color:#999999\&quot;&gt;:&lt;/span&gt;\n                    fw&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;write&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;rmp3&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;content&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n                &lt;span style=\&quot;color:#0077aa\&quot;&gt;print&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;&lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;Down Successful! \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; &lt;span style=\&quot;color:#50a14f\&quot;&gt;\&quot;file path is \&quot;&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;,&lt;/span&gt; os&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;path&lt;span style=\&quot;color:#999999\&quot;&gt;.&lt;/span&gt;dirname&lt;span style=\&quot;color:#999999\&quot;&gt;(&lt;/span&gt;__file__&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;&lt;span style=\&quot;color:#999999\&quot;&gt;)&lt;/span&gt;\n\n&lt;span style=\&quot;color:#708090\&quot;&gt;# 如果要運行此程式 請打開下面的注釋&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a = DownOneMp3()&lt;/span&gt;\n&lt;span style=\&quot;color:#708090\&quot;&gt;# a.spider()&lt;/span&gt;\n\n&lt;/code&gt;&lt;/span&gt;&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><span style="color:#708090"># -*- coding :  utf-8 -*-</span>
<span style="color:#708090"># @Time      :  2020/9/17  21:35</span>
<span style="color:#708090"># @author    :  沙漏在下雨</span>
<span style="color:#708090"># @Software  :  PyCharm</span>
<span style="color:#708090"># @CSDN      :  https://me.csdn.net/qq_45906219</span>
<span style="color:#0077aa">import</span> requests
<span style="color:#0077aa">from</span> get_useragent <span style="color:#0077aa">import</span> GetUserAgentCS
<span style="color:#0077aa">from</span> GetParams <span style="color:#0077aa">import</span> GetParams
<span style="color:#0077aa">from</span> DownMp3 <span style="color:#0077aa">import</span> DownMp3


<span style="color:#0077aa">class</span> DownOneMp3<span style="color:#999999">(</span>DownMp3<span style="color:#999999">)</span><span style="color:#999999">:</span>
    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">__init__</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">super</span><span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>__init__<span style="color:#999999">(</span><span style="color:#999999">)</span>
        self<span style="color:#999999">.</span>GetIdUrl <span style="color:#a67f59">=</span> <span style="color:#50a14f">"https://music.163.com/weapi/cloudsearch/get/web?csrf_token="</span>
        self<span style="color:#999999">.</span>params_url <span style="color:#a67f59">=</span> <span style="color:#50a14f">"https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token="</span>
        self<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> GetUserAgentCS<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_user<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">}</span>
        self<span style="color:#999999">.</span>start <span style="color:#a67f59">=</span> <span style="color:#50a14f">input</span><span style="color:#999999">(</span><span style="color:#50a14f">"Please input the music name:"</span><span style="color:#999999">)</span>
        ids <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_id<span style="color:#999999">(</span><span style="color:#999999">)</span>
        self<span style="color:#999999">.</span>params <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>get_params<span style="color:#999999">(</span><span style="color:#50a14f">id</span><span style="color:#a67f59">=</span>ids<span style="color:#999999">)</span>
        self<span style="color:#999999">.</span>mp3_name <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>start <span style="color:#a67f59">+</span> <span style="color:#50a14f">".mp3"</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">my_request</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> url<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"get"</span><span style="color:#999999">,</span> params<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">"""
        繼承父類的一個方法
        """</span>
        <span style="color:#0077aa">return</span> <span style="color:#50a14f">super</span><span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>url<span style="color:#999999">,</span> model<span style="color:#999999">,</span> params<span style="color:#999999">)</span>

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_params</span><span style="color:#999999">(</span>self<span style="color:#999999">,</span> <span style="color:#50a14f">id</span><span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""給出id 回傳加密引數"""</span>
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span><span style="color:#50a14f">"ids"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span><span style="color:#999999">[</span><span style="color:#50a14f">id</span><span style="color:#999999">]</span><span style="color:#999999">)</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">""</span><span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">return</span> params

    <span style="color:#0077aa">def</span> <span style="color:#dd4a68">get_id</span><span style="color:#999999">(</span>self<span style="color:#999999">)</span><span style="color:#999999">:</span>
        <span style="color:#50a14f">"""
        根據歌曲名稱獲取id
        """</span>
        start <span style="color:#a67f59">=</span> self<span style="color:#999999">.</span>start
        d <span style="color:#a67f59">=</span> <span style="color:#999999">{</span>
            <span style="color:#50a14f">"hlpretag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"<span class=\"s-fc7\">"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"hlposttag"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"</span>"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"s"</span><span style="color:#999999">:</span> <span style="color:#50a14f">str</span><span style="color:#999999">(</span>start<span style="color:#999999">)</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"type"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"1"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"offset"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"0"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"total"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"true"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"limit"</span><span style="color:#999999">:</span> <span style="color:#50a14f">"30"</span><span style="color:#999999">,</span>
            <span style="color:#50a14f">"csrf_token"</span><span style="color:#999999">:</span> <span style="color:#50a14f">""</span>
        <span style="color:#999999">}</span>
        params <span style="color:#a67f59">=</span> GetParams<span style="color:#999999">(</span><span style="color:#999999">)</span><span style="color:#999999">.</span>get_encrypt_params<span style="color:#999999">(</span><span style="color:#50a14f">str</span><span style="color:#999999">(</span>d<span style="color:#999999">)</span><span style="color:#999999">)</span>
        <span style="color:#0077aa">return</span> self<span style="color:#999999">.</span>my_request<span style="color:#999999">(</span>self<span style="color:#999999">.</span>GetIdUrl<span style="color:#999999">,</span> model<span style="color:#a67f59">=</span><span style="color:#50a14f">"post"</span><span style="color:#999999">,</span> params<span style="color:#a67f59">=</span>params<span style="color:#999999">)</span><span style="color:#999999">[</span><span style="color:#50a14f">"result"</span><span style="color:#999999">]</span><span style="color:#999999">[</span><span style="color:#50a14f">"songs"</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">"id"</span><span style="color:#999999">)</span>

    <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">"""
        這是爬取一首歌的方式, 你只需要輸入歌曲名稱就可以 會自動呼叫其他類實作引數加密 id獲取等
        """</span>

        <span style="color:#0077aa">import</span> os
        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>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span>r<span style="color:#999999">.</span>json<span style="color:#999999">(</span><span style="color:#999999">)</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>
            <span style="color:#0077aa">print</span><span style="color:#999999">(</span><span style="color:#50a14f">"music link is "</span><span style="color:#999999">,</span> mp3<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>self<span style="color:#999999">.</span>headers<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>self<span style="color:#999999">.</span>mp3_name<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">"Down Successful! "</span><span style="color:#999999">,</span> <span style="color:#50a14f">"file path is "</span><span style="color:#999999">,</span> os<span style="color:#999999">.</span>path<span style="color:#999999">.</span>dirname<span style="color:#999999">(</span>__file__<span style="color:#999999">)</span><span style="color:#999999">)</span>

<span style="color:#708090"># 如果要運行此程式 請打開下面的注釋</span>
<span style="color:#708090"># a = DownOneMp3()</span>
<span style="color:#708090"># a.spider()</span>

</code></span>

關于__init__ :

/"/"/"/n如果你僅僅只是想下載一首歌 跳轉到DownOneMp3模塊啟動模塊運行/n如果你想多首歌發送某人郵箱  跳轉到DownMp3模塊啟動模塊運行/n/"/"/"/n","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="color:#000000"><code ><span style="color:#50a14f">"""
如果你僅僅只是想下載一首歌 跳轉到DownOneMp3模塊啟動模塊運行
如果你想多首歌發送某人郵箱  跳轉到DownMp3模塊啟動模塊運行
"""</span>
</code></span>

JS逆向, ASE加密, RES非對稱演算法,yagmail郵箱的發送,瀏覽器的debug,學到就是爽,

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113542.html

標籤:Python

上一篇:做量化交易的第一步,Python爬取股票資料

下一篇:Python入門級爬蟲教材,獲取天天基金網站的基金資料

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more