贴上代码和报错,用<>代码格式。 不知道为什么的我的帖子不见了? 想读取这个评论:https://music.163.com/#/playlist?id=925845034
import requests
def get_comments(url):
# name_id = url.split("=")
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
"referer":"https://music.163.com/playlist?id=925845034"
}
params = "no-cache"
data = {
"params": params
}
target_url = "https://music.163.com/weapi/comment/resource/comments/get?csrf_token="
res = requests.post(target_url, headers=headers, data=data)
return res
def main():
url = input("输入网址:")
res = get_url(url)
with open("res.txt","w",encoding="utf-8") as file:
file.write(res.text)
if __name__ == " __main__":
main()
出现的错误是:
"referer":"https://music.163.com/playlist?id=925845034"
^
SyntaxError: invalid syntax suchocolate 发表于 2022-7-15 09:08
贴上代码和报错,用代码格式。
好的~麻烦帮我看看。爬虫小白找不到原因。 报错提示的意思是语法错误,然后去到那行看,发现字典元素之间没有逗号。
换个IDLE吧,pycharm或vscode都会自动提示语法错误,这么简单的问题来发帖浪费时间。
页:
[1]