import requestsas rq from bs4import BeautifulSoup import pandasas pd import numpyas np import time import concurrent.futures from multiprocessing.dummyimport Poolas pool ##后面所有的代码都是调的这些个库,我习惯写pd np因为懒。。。 list1=[] headers={'Referer':'http://music.163.com/','Host':'music.163.com','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'}defgetHTMLText(url,headers):#通用的获取网站内容的框架try: r= rq.get(url,headers=headers) r.raise_for_status() r.encoding= r.apparent_encodingreturn r.textexcept:return"网络解析错误"defget_url(cat):#获取首页该分类下面的歌单url,形成url_list depth=38 start_url='https://music.163.com/discover/playlist/?order=hot&cat='+catfor iinrange(depth):try: url=start_url+'&limit=35'+'&offset='+str(35*(i+1)) html=getHTMLText(url,headers) parse_main(html)except:print('失败')continuedefparse_main(html):#解析每个广场页,bs4弄出来歌单名,歌单URL soup=Beautiful