代码出错了?该怎么办?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码出错了?该怎么办?相关的知识,希望对你有一定的参考价值。
url = 'https://music.163.com/discover/toplist?id='
a = input('请输入榜单的ID:')
部分代码如下:
a_url = a+url
base_url = 'https://music.163.com/song/media/outer/url?id='
# a = input('请输入歌单的ID:')
file = "C:/Users/Administrator/pycharmProjects/pythonProject1/网易云音乐/" # 保存音乐的文件路径,最后加斜杠
headers = 'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
# b_url = "https://link.hhtjim.com/163/"
x = requests.session()
list_url = requests.get(a_url, headers=headers).content
xy = BeautifulSoup(list_url, features="lxml")
main = xy.find('ul', 'class': 'f-hide')
ls = main.find_all('a')
for music in ls:
song_id = str(music['href']).replace('/song?id=', '')
w_url = "https://music.163.com/song?id=" + song_id
song_url = base_url + song_id + ".mp3"
# 获取歌曲
song = requests.get(song_url).content
结果:Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythonProject1/热榜爬取.py", line 15,<module>
list_url = requests.get(a_url, headers=headers).content
File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 649, in send
adapter = self.get_adapter(url=request.url)
File "C:\Users\Administrator\PycharmProjects\pythonProject1\venv\lib\site-packages\requests\sessions.py", line 742, in get_adapter
raise InvalidSchema("No connection adapters were found for !r".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for '3778678https://music.163.com/discover/toplist?id='
Process finished with exit code 1
url = 'https://music.163.com/discover/toplist?id='
a = input('请输入榜单的ID:')
部分代码如下:
a_url = a+url 这里拼接后确定没有问题?
base_url = 'https://music.163.com/song/media/outer/url?id='
# a = input('请输入歌单的ID:') 参考技术A 按f12调试
求助,win10下MDK5编译例程出错,怎么解决
参考技术A 1.检查电脑是否存在病毒,请使用百度卫士进行木马查杀。2.系统文件损坏或丢失,盗版系统或Ghost版本系统,很容易出现该问题。建议:使用完整版或正版系统。
3.安装的软件与系统或其它软件发生冲突,找到发生冲突的软件,卸载它。如果更新下载补丁不是该软件的错误补丁,也会引起软件异常,解决办法:卸载该软件,重新下载重新安装试试。顺便检查开机启动项,把没必要启动的启动项禁止开机启动。
4.如果检查上面的都没问题,可以试试下面的方法。
以上是关于代码出错了?该怎么办?的主要内容,如果未能解决你的问题,请参考以下文章
Oracle Database 下载第一个压缩文件就安装了,导致出错,该怎么办呢?