In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.