import requests
from bs4 import BeautifulSoup
import pandas as pd
titles=[]
hots=[]
url='

https://y.qq.com/n/yqq/toplist/4.html
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/69.0.3497.100 Safari/537.36'}
r=requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
html = r.text
table = BeautifulSoup(html,"html.parser").find("table")
soup=BeautifulSoup(html,'lxml')
for m in soup.find_all(class_="topic-text"):
titles.append(m.get_text().strip())
for n in soup.find_all(class_="topic-num"):
hots.append(n.get_text().strip())
final=[titles,hots]
print(final)
s=pd.DataFrame(final,index=["歌曲名称","播放次数"])
print(s.T)

posted @ 2020-03-21 10:59  悠01  阅读(154)  评论(0编辑  收藏  举报