Home  >  Article  >  Backend Development  >  Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

little bottle
little bottleforward
2019-04-02 14:19:082382browse



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.

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

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.

640 (1).gif

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

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

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(&#39;[Warning]:_GetSongsInfo <links> not find...&#39;)
    Info = {&#39;ID&#39;: [], &#39;NAME&#39;: []}
    for link in links:
        SongID = link.get(&#39;href&#39;).split(&#39;=&#39;)[-1]
        SongName = link.get_text()
        Info[&#39;ID&#39;].append(SongID)
        Info[&#39;NAME&#39;].append(SongName)
    # print(Info)
    return Info


def GetLyrics(SongID):
    print(&#39;[INFO]:Getting %s lyric...&#39; % SongID)
    ApiUrl = &#39;http://music.163.com/api/song/lyric?id={}&lv=1&kv=1&tv=-1&#39;.format(SongID)
    html = GetHtml(ApiUrl)
    html_json = json.loads(html)
    temp = html_json[&#39;lrc&#39;][&#39;lyric&#39;]
    rule = re.compile(r&#39;\[.*\]&#39;)
    lyric = re.sub(rule, &#39;&#39;, temp).strip()
    print(lyric)
    return lyric


def main():
    SingerId = input(&#39;Enter the Singer ID:&#39;)
    url = &#39;http://music.163.com/artist?id={}&#39;.format(SingerId)
    # url = "http://music.163.com/artist?id=6457"
    Info = GetSongsInfo(url)
    IDs = Info[&#39;ID&#39;]
    i = 0
    for ID in IDs:
        lyric = GetLyrics(ID)
        SaveLyrics(Info[&#39;NAME&#39;][i], lyric)
        i += 1
        time.sleep(random.random() * 3)
        # print(&#39;[INFO]:All Done...&#39;)


def SaveLyrics(SongName, lyric):
    print(&#39;[INFO]: Start to Save {}...&#39;.format(SongName))
    if not os.path.isdir(&#39;./results&#39;):
        os.makedirs(&#39;./results&#39;)
    with open(&#39;./results/{}.txt&#39;.format(SongName), &#39;w&#39;, encoding=&#39;utf-8&#39;) 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.

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

03

##《A Chinese Ghost Story》

Beautiful Dreams in the Red Dust How many directions are there

Looking for the love of the crazy dream

The road is endless with people

640 (2).gif

In "A Chinese Ghost Story", you are shy The timid scholar would light three lanterns when walking at night, but for fear that the sunlight would scatter Xiaoqian's soul, he would hold the door panel firmly on his shoulders.

Xiaoqian left, and Ning Caichen's heart died.

My brother is gone, and if someone else plays Ning Caichen, I always feel that Wushan is not Yun.

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.

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

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

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

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.

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

Python crawls Leslie Cheung’s 8 most popular songs, with 60,000 comments and I burst into tears after reading them!

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


##"Glass Love"

Don’t believe in tears It can make you fall in love again when you are disappointed.

The hard-to-recover water will spread the feelings away

There is no crime in saying goodbye in time if you are too tired


You once said that every time you sing, you have to make up a story for the song. When you sing, the picture of the story comes to your mind, and this sense of picture makes you very immersed in singing.


Why your songs last forever is because you not only attach great importance to people, but also to songs.

08

《When the Wind Rises Again》


I look back to a certain year

Like a faded photo appearing before my eyes

This confused boy

May I devote my life to singing every day and never change


In 1989, having seen too many ups and downs in the entertainment industry, you suddenly announced your farewell to the music industry.


You have seen the hustle and bustle, but you are not part of the hustle and bustle.


Before planning the farewell concert, you discussed it with musicians Chen Shaoqi and Li Xiaotian.

Chen Shaoqi said, "Don't you have a famous song called "The Wind Continues to Blow"? Why don't you just call it "When the Wind Rises Again"? I just hope that when the wind blows again, fans will think of you." Song."

Li Xiaotian next to him spent fifteen minutes composing the song on a random piece of paper.

Soon, Chen Shaoqi also filled in the words.

Some people say that the lyrics in this song are tailor-made for you: "I look back to a certain year, and like a faded photo suddenly appears in front of my eyes, this confused young man is willing to sing and devote himself to it all his life. It never changes every day.”


May I spend my whole life singing and devoting myself to every day forever...

640 (3).gif


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!

Statement:
This article is reproduced at:程序人生 coder_life. If there is any infringement, please contact admin@php.cn delete