import requests
import random
import time
from bs4 import BeautifulSoup
datas = []
headers = [
{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36 Edg/81.0.416.45"},
{"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4094.1 Safari/537.36"},
{"User-Agent": "Mozilla/5.0 (Windows NT 6.1; rv,2.0.1) Gecko/20100101 Firefox/4.0.1"},
{"User-Agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)"},
{"User-Agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"},
{"User-Agent": "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0"}
]
header = random.choice(headers)
def get_info(url):
res = requests.get(url, header)
print(res.status_code)
soup = BeautifulSoup(res.text,'lxml')
links = soup.select('span.pc_temp_num')
singers = soup.select('div.pc_temp_songlist>ul>li>a')
times = soup.select('span.pc_temp_tips_r')
for link, singer, sing, time in zip(links, singers,singers,times):
datas.append(
{
"lniks" : link.get_text().strip(),
"singer" : singer.get_text().split('-')[0],
"sing" : singer.get_text().split('-')[1],
"time" : time.get_text().strip().split('\t')[-1]
}
)
for i in datas:
print(i)
if __name__ == "__main__":
urls = ['https://www.kugou.com/yy/rank/home/{}-8888.html'.format(str(i)) for i in range(1,24)]
for i in urls:
get_info(i)
print('-' *100)
time.sleep(1)
|