diff --git a/src/main.py b/src/main.py index 6377e72..bc62916 100644 --- a/src/main.py +++ b/src/main.py @@ -70,10 +70,27 @@ return "" +def getMusicList(url, retry): + try: + res = requests.get(root_url,verify=False, timeout=20) + content = res.content + res.close() + return content + except: + if retry > 3: + return "" + time.sleep(1) + print("unable to access the kuwo.cn. Retries: ") + getMusicList(url, retry+1) -res = requests.get(root_url,verify=False, timeout=20) -body = BeautifulSoup(str(res.content), "html.parser") -res.close() + + + +content = getMusicList(root_url, 0) +if content == "" : + print("Unable to access the music list. Exit") + exit(0) +body = BeautifulSoup(str(content), "html.parser") new_music_count = 0 for item in body.find_all("div", {"class", "tools"}): json_payload=item["data-music"].replace("'","").replace("\\","")