爬虫 抓取酷狗音乐排行榜作者和歌名,并写入文件
import requests
import re
def page():
response=requests.get("http://www.kugou.com/yy/html/rank.html")
return response.text
def parse(html):
patter = re.compile('<li class=.*?title="(.*?)"',re.S)
item=patter.findall(html)
return item
if __name__ =='__main__':
print(page())
html=page()
for iin parse(html):
with open("2xx.txt","a+",encoding="utf-8")as f:
f.write(str(i) +"\n")