current position:Home>Python implements JS encryption algorithm in thousands of music websites

Python implements JS encryption algorithm in thousands of music websites

2022-01-29 16:10:18 White and white I

Little knowledge , Great challenge ! This article is participating in “   A programmer must have a little knowledge   ” Creative activities

This article also participates in  「 Digging force Star Program 」  , Win a creative gift bag , Challenge creation incentive fund

Web crawler

Web crawler , I don't know if you know ? Today, I'm writing to you for nothing to understand the... In thousands of music websites JS encryption algorithm , If anything is wrong , Please correct me .

You who want to learn reptiles with me , Then you must first master some basic knowledge about reptiles , To know what a reptile is ? Where does the data come from ? First understand some basic knowledge points before you can really learn reptiles . Basic knowledge problems can be found on the Internet , Hee hee

image.png

My understanding of the crawler's work is to simulate the process of getting Web information through the browser , Nothing more “ Send a request — Get the page — Parsing the page — Extract and store content ” From this process , The information we can get is , In the crawler work, you need to involve the knowledge related to the front-end page , Knowledge of network protocol , And knowledge of data storage . Therefore, according to this process, we need to further master more technologies .

Crawlers have many functions in the Internet world , such as : Data collection \ Grab microblog comments ( Machine learning public opinion monitoring )\ Grab the recruitment information from the recruitment website ( Data analysis 、 mining )\ Sina rolling news \ Baidu news website \ software test \ Automated testing of crawlers \ Insect division \12306 Grab tickets \ Voting on the website \ Network security \ SMS bombing \web Vulnerability scanning and other useful, fun and interesting purposes .

image.png

To enter the body

Climb to the target

Website : Thousands of music - The wind blows (taihe.com)

123.png

Tool use

development tool :pycharm development environment :python3.7, Windows10 Using third party libraries :requests,time, hashlib

Focus on learning content

sign Parameter encryption

url Request parameter splicing

The use of timestamps

Page analysis

First, go to the music playing page Find the playback address

First step : Open the web page , Right click to check , Then click play music The second step : Select media interface The third step : To locate the interface when playing music , Because there is a separate interface when playing music

See the following figure for details :

234.png

Note that copying this suffix Used to search Look at the interface where the playback address contains

345.png

then ctrl+f Enter the keyword for the search

456.png

567.png

678.png

sign The generation location is return Put a breakpoint in front , See the following pictures

789.png

8910.png

Note the encryption location md5 encryption algorithm , then r It's a request parameter , therefore seret The fixed string declared above .

91011.png

Code implementation

import hashlib
import time
import requests
​
​
time1 = int(time.time())
r = f"TSID=T10046047408&appid=16073360&timestamp={time1}" + '0b50b02fd0d73a9c4c8c3a781c30845f'
byte_row = r.encode('utf-8', 'ignore')
md5 = hashlib.md5()
md5.update(byte_row)
sign = md5.hexdigest()
​
url = f'https://music.taihe.com/v1/song/tracklink?sign={sign}&appid=16073360&TSID=T10046047408&timestamp={time1}'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38'
}
response = requests.get(url, headers=headers).json()
print(response)
 Copy code 

image.png

I am white and white i, A program Yuan who likes to share knowledge ️
Interested can pay attention to my official account : White and white Python【 Thank you very much for your praise 、 Collection 、 Focus on 、 Comment on , One key three links support 】

copyright notice
author[White and white I],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201291610176215.html

Random recommended