How to write the source code of KuGou music crawled by Python crawler
Today, I will talk to you about how to write the source code of KuGou music crawled by Python crawler. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
In several common music websites, KuGou can be said to be the best to crawl. There are no bends and no encryption, so it is the most suitable for rookie entry crawlers.
Project source code
Import requestsfrom selenium import webdriverfrom pyquery import PyQuery as pq
# get the song title def Access_to_the_song (C): doc=pq (C) The_song=doc ('.audioName'). Text () return The_song
# enter the music interface to climb HTMLdef Browser_access (URL): The_browser=webdriver.ChromeOptions () The_browser.set_headless () Drier=webdriver.Chrome (options=The_browser) Drier.get (URL) Print_source=Drier.page_source doc = pq (Print_source) Music_links = doc ('.music') .items () for i in Music_links: Music_downloads = i.attr ('src') With open (Access_to_the_song (Print_source) + '.mp3' 'wb') as p: p.write (requests.get (Music_downloads) .content)
# crawling popular songs
Def Music_links (): URL = 'http://www.kugou.com/yy/rank/home/1-6666.html?from=rank' headers= {' User-Agent':'Mozilla/5.0 (Windows NT 10.0) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'} response = requests.get (URL,headers=headers). Text doc = pq (response) test = doc ('.pc _ temp_songname'). Items () for i in test: C = i.attr (' href') Browser_access (c)
Music_links () after reading the above, do you have any further understanding of how to write the source code of KuGou music crawled by Python crawler? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.