from selenium import webdriver
import csv
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument(‘--headless‘)
chrome_options.add_argument(‘--disable-gpu‘)
driver = webdriver.Chrome(options=chrome_options)
url1 = ‘http://music.163.com/#/discover/playlist/?order=hot&cat=%E5%85%A8%E9%83%A8&limit=35&offset=‘
offset = 0
#准备好存储歌单的csv文件
csv_file = open(“playlist.csv“‘w‘newline=‘‘)
writer = csv.writer(csv_file)
writer.writerow([‘标题‘‘播放数‘‘链接‘])
#解析每一页,直到‘下一页’为空
for page in range(2):
print(‘\n 正在爬取第%d页。。。‘%page‘\n‘)
url = url1+str(offset)
offset = offset+35
print(‘ ‘url ‘\n‘)
#用webDriver加载页面
评论
共有 条评论