Home >Backend Development >Python Tutorial >Python crawls Leslie Cheung's 8 most popular songs, with 60,000 comments and I burst into tears after reading them!
Yesterday was April 1st.
On this day every year,
some people search hard and think of ways to play tricks,
some people feel that April would be great, if you are still here.
There are even people who use AI to restore you.
But it’s not you after all.
See watermark for picture source
It’s been 16 years since you left. Those teenagers who secretly listened to your songs at the desk when the teacher wasn’t paying attention, Perhaps she has been a husband and a wife for a long time.
Even so, every year, many people miss you and leave you messages through the endless echoes you leave to the world in April. Even if they know it clearly, they will never A reply will be received.
Now, we choose to use technology to commemorate our brother.
We crawled your eight songs with the most comments on NetEase Cloud Music.
They are: "Silence is Golden", "Spring, Summer, Autumn and Winter", "A Chinese Ghost Story", "When Love Is a Past", "Me", "The Wind Keeps Blowing", "The Love of Glass" and "When the Wind Rises Again".
Among the 64,540 comments in total, the most common ones were "Happy birthday," "Brother," "Come on," "If you are still here," "Happy New Year," and "Happy birthday, brother."
There are very few words like "April 1st" and "April Fool's Day" in the word cloud chart. This is not because there are few people commenting on this day, but because On this day, it is really not the right time to say "Happy" to you.
Come on, let me show you the code of the comment first.
# coding:utf-8 import json import time import requests from fake_useragent import UserAgent import random import multiprocessing import sys #reload(sys) #sys.setdefaultencoding('utf-8') ua = UserAgent(verify_ssl=False) song_list = [{'186453':'春夏秋冬'},{'188204':'沉默是金'},{'188175':'倩女幽魂'},{'188489':'风继续吹'},{'187374':'我'},{'186760':'风雨起时'}] headers = { 'Origin':'https://music.163.com', 'Referer': 'https://music.163.com/song?id=26620756', 'Host': 'music.163.com', 'User-Agent': ua.random } def get_comments(page,ite): # 获取评论信息 # """ for key, values in ite.items(): song_id = key song_name = values ip_list = [IP列表] url = 'http://music.163.com/api/v1/resource/comments/R_SO_4_'+ song_id +'?limit=20&offset=' + str(page) proxies = get_random_ip(ip_list) try: response = requests.get(url=url, headers=headers,proxies=proxies) except Exception as e: print (page) print (ite) return 0 result = json.loads(response.text) items = result['comments'] for item in items: # 用户名 user_name = item['user']['nickname'].replace(',', ',') # 用户ID user_id = str(item['user']['userId']) print(user_id) # 评论内容 comment = item['content'].strip().replace('\n', '').replace(',', ',') # 评论ID comment_id = str(item['commentId']) # 评论点赞数 praise = str(item['likedCount']) # 评论时间 date = time.localtime(int(str(item['time'])[:10])) date = time.strftime("%Y-%m-%d %H:%M:%S", date)
Lyric codes for eight songs:
import requests from bs4 import BeautifulSoup import re import json import time import random import os headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.4 Safari/537.36', 'Referer': 'http://music.163.com', 'Host': 'music.163.com' } # 获取页面源码 def GetHtml(url): try: res = requests.get(url=url, headers=headers) except: return None return res.text # 提取歌手歌词信息 def GetSongsInfo(url): print('[INFO]:Getting Songs Info...') html = GetHtml(url) soup = BeautifulSoup(html, 'lxml') links = soup.find('ul', class_='f-hide').find_all('a') if len(links) < 1: print('[Warning]:_GetSongsInfo <links> not find...') Info = {'ID': [], 'NAME': []} for link in links: SongID = link.get('href').split('=')[-1] SongName = link.get_text() Info['ID'].append(SongID) Info['NAME'].append(SongName) # print(Info) return Info def GetLyrics(SongID): print('[INFO]:Getting %s lyric...' % SongID) ApiUrl = 'http://music.163.com/api/song/lyric?id={}&lv=1&kv=1&tv=-1'.format(SongID) html = GetHtml(ApiUrl) html_json = json.loads(html) temp = html_json['lrc']['lyric'] rule = re.compile(r'\[.*\]') lyric = re.sub(rule, '', temp).strip() print(lyric) return lyric def main(): SingerId = input('Enter the Singer ID:') url = 'http://music.163.com/artist?id={}'.format(SingerId) # url = "http://music.163.com/artist?id=6457" Info = GetSongsInfo(url) IDs = Info['ID'] i = 0 for ID in IDs: lyric = GetLyrics(ID) SaveLyrics(Info['NAME'][i], lyric) i += 1 time.sleep(random.random() * 3) # print('[INFO]:All Done...') def SaveLyrics(SongName, lyric): print('[INFO]: Start to Save {}...'.format(SongName)) if not os.path.isdir('./results'): os.makedirs('./results') with open('./results/{}.txt'.format(SongName), 'w', encoding='utf-8') as f: f.write(lyric)
01
"Silence is Golden"
It’s wrong, it’s never right, it’s always true
No matter what you say, I’ll stick to my duty
Always believe silence is golden
This song was composed by you yourself.
At that time, the "Tan-Chang Hegemony" (from 1986 to 1989, Alan Tam and Leslie Cheung launched a comprehensive competition in music to compete for status in the music industry) had entered a fever pitch.
You hate fighting, so you borrowed a song to express your ambition and released "Silence is Golden".
You said, "No matter what you say, I will stick to my duty and always believe that silence is golden."
The pure will purify themselves, and your silence will further demonstrate your innocence.
02
《Spring, Summer, Autumn and Winter》
Autumn should be great if you are still here
Even if the autumn wind is cool, it is still beautiful
You in the late autumn fill my dreams
Like fallen leaves flying and tapping on my window
Every time it’s your birthday, every New Year, or every day you leave this world, there will be a lot of comments under your songs.
You left on April 1st, but people who like you always come to comment on your music on March 30th, 31st or even earlier.
So many people hope that you will be resurrected. Some people even saw a taxi driver in Chongqing who looked very similar to you and couldn't help but take a picture.
The clarity and hesitation in your eyes are still so unforgettable after all these years.
03
04
##"When Love Is a Past"
Why don’t you understand
As long as there is love, there will be pain
One day you will know
Life will not be different without me
In "Farewell My Concubine", you played Cheng Dieyi.
You acted so charmingly that some people asserted that you were born in Tongzi Gong.
Actually, you are just continuing to train despite being seriously ill.
You said "If you don't go crazy, you won't survive", so you know that after Duan Xiaolou marries a wife, he will be jealous, sad and crazy.
You have loved both on and off the screen. You said, "As long as there is love, there will be pain", but it is more like singing it to yourself.
You are so pure and "accepting death" that your fans always feel sorry for you...
05
《我》
The same nakedness that blooms in the lonely desert
How happy Live happily in the glass house
What is light and aboveboard to the world
I am I am fireworks with different colors
How many people use the phrase you sang, "I am who I am, just like fireworks of different colors" to encourage themselves to live out their lives.
But in the end you left this world like fireworks.
A few years ago, Tony Leung dialed your phone number at a concert to commemorate you.
On the phone, the message was still there, "Hello, I'm Leslie, please leave a message if you need anything."
Liang Chaowei was silent, and after a long time, he said calmly Sentence: "Baorong, why don't we start from scratch."
06
《风continues to blow》
The wind continues to blow and I can’t bear to stay away
There are tears in my heart and I don’t want to shed tears as I look at you
So many happy memories in the past
Why not chase it with you
This is your famous song, so you seem to like it very much.
Every time I attend a concert, I have to sing.
When you sang for the last time, you cried for some reason, and the audience also cried with you.
Because this song is a testimony of your turnaround.
You have been in the music industry for so many years, but you have always been silent. This song has prevented you from being buried.
07
08
I wonder if you are still singing now? Are you still acting?
Do you know that many people are thinking of you.
Thank you for leaving us so many songs and movies.
May you never be depressed or sad in another world.
above.
This article has ended here. For more exciting content, you can pay attention to the Python Video Tutorial column on the PHP Chinese website! ! !
The above is the detailed content of Python crawls Leslie Cheung's 8 most popular songs, with 60,000 comments and I burst into tears after reading them!. For more information, please follow other related articles on the PHP Chinese website!