Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Python crawl sound material

Shulou Source: shulou.com Published: 2022-06-01 20:08:34 09月28日 Update

This article mainly introduces "how Python crawls sound materials". In daily operation, I believe many people have doubts about how Python crawls sound materials. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how Python crawls sound materials". Next, please follow the editor to study!

Project goal

Crawl sound effect material

Victim address

Http://sc.chinaz.com/yinxiao/

Crawler code

Import tool

Import requestsimport parsel

Request website

Url= 'http://sc.chinaz.com/yinxiao/index_{}.html'.format(page) headers= {' User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'} response = requests.get (url=url, headers=headers)

Parsing website data and crawling data

Selector = parsel.Selector (response.text) urls = selector.css ('# musiclist .n1:: attr (thumb)'). Getall () titles = selector.css ('# musiclist .z a::attr (alt)'). Getall () data = zip (urls, titles) for i in data: print (I) download_url = I [0] title = I [1] response_2 = requests.get (url=download_url, headers=headers)

Save data

Filename ='C:\\ Users\\ Administrator\\ Desktop\\ create a new folder\'+ title + '.mp3' with open (filename, mode='wb') as f: f.write (response_2.content)

Run the code, and the effect is as follows

At this point, the study of "how Python crawls sound material" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Materials sound effects learning data websites code more help utility next victims addresses tools effects files folders articles methods crawlers theory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Shulou Information Docker macOS