今天在網上閒逛的時候發一下比較好的音樂下載網址,輸入歌手名字有歌手全部的音樂,還可以下載無損音質的音樂
作為爬蟲的愛好者,對此不得給安排一下?
實現代碼import timeimport requestsfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Options
chrome_options = Options()chrome_options.add_argument('--headless')driver = webdriver.Chrome(executable_path='chromedriver.exe', options=chrome_options)driver.implicitly_wait(10)driver.get('http://tool.liumingye.cn/music/?page=searchPage')driver.find_element_by_css_selector('#input').send_keys('張杰')driver.find_element_by_css_selector('#search button:nth-child(2) i').click()
"""保存歌曲數據"""def download(name, url): filename = '音樂\\' + name + '.mp3' response = requests.get(url=url) with open(filename, mode='wb') as f: f.write(response.content)
"""模擬人去滾動滑鼠向下瀏覽頁面"""def drop_down(): for x in range(1, 20, 10): time.sleep(0.5) j = x / 10 js = 'document.documentElement.scrollTop = document.documentElement.scrollHeight * %f' % j driver.execute_script(js)
"""解析網站數據獲取歌曲名字以及歌曲下載地址"""lis = driver.find_elements_by_css_selector('#player li')f = 0for li in lis: f += 1 time.sleep(1) name = li.find_element_by_css_selector('.aplayer-list-title').text li.find_element_by_css_selector('.aplayer-list-download').click() time.sleep(1) down_url = driver.find_element_by_css_selector('#m-download > div > div > div.modal-body > div:nth-child(6) > div.input-group-append > a.btn.btn-outline-secondary.download').get_attribute('href') time.sleep(1) driver.find_element_by_css_selector('#m-download > div > div > div.modal-header > button').click() download(name, down_url) print(name, down_url) if f % 10 == 0: drop_down()【爬取效果】
掃下方二維碼加老師微信或是搜索老師微信號:XTUOL1988【備註學習Python】領取Python web開發,Python爬蟲,Python數據分析,人工智慧等學習教程。帶你從零基礎系統性的學好Python!也可以加老師建的Python技術學習教程qq裙:245345507,二者加一個就可以!
歡迎大家點讚,留言,轉發,轉載,感謝大家的相伴與支持
萬水千山總是情,點個【在看】行不行
*聲明:本文於網絡整理,版權歸原作者所有,如來源信息有誤或侵犯權益,請聯繫我們刪除或授權事宜。