|
楼主 |
发表于 2023-5-26 16:23:08
|
显示全部楼层
# @Time:2023/5/2613:27
# @Author:YL
# @File:pachong_wangyiyun.py
# @Software:PyCharm
import requests
import bs4
import re
import openpyxl
import json
def open_url(url):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42',
'referer': 'https: // music.163.com /'}
# res = requests.get(url, headers=headers, proxies=proxies)
params = "EuIF/+GM1OWmp2iaIwbVdYDaqODiubPSBToe5EdNp6LHTLf+aID/dWGU6bHWXS0jD9pPa/oY67TOwiicLygJ+BhMkOX/J1tZMhq45dcUIr6fLuoHOECYrOU6ySwH4CjxxdbW3lpVmksGEdlxbZevVPkTPkwvjNLDZHK238OuNCy0Csma04SXfoVM3iLhaFBT"
encSecKey = "db26c32e0cd08a11930639deadefda2783c81034be6445ca8f4fbedd346e1f9567375083aeb1a85e6ad6d9ae4532a49752c2169db8bcc04d38a79f9bed7facea42ee23f1b33538c34f82741318d9b4b846663b53b0b808dd0499dccfbc6c61fbf180c6fb24b1c2dd3c2c450ce09917d74be9424dab836fd2e671988ffbc6ae1b"
# encSecKey = " 6d407605344a08d156d8dd7251c756b8c98a69ef8dd670ffcdc5d7db0019cbfa283a07707363c9a54a6d749b2fceda32b4e450d2988741f4c48df304263fa213de85ec14425bf2c5cd3c64c3fd7bf90d9bfed66438d02c8d60078a09ecc2273be30aa6fbe4082c3dd3f18cb23efbfeab6f6209c173147b6f8f768be296c6a5b5"
# params = "aYI5Lgk6cIIEOKVLrbjf3jakQsRFxSFygJEu7CJ5pQ + YHT5Jgt3KLeFlUAKCp2zZDrfz + a1eSoRNJa + RWGsRaT + O1k3wGP6IgB8qd3oPjas2rpqngCgxh9ymYk2z0Qn4gU8pd2cJ8uiEBsTT3S0d5tLOEUAS + qbjRD9gI / H3XGeRNH8HBTUBz0 / P / cB4dvFcKS76lynAiuzZiHdrgmcWDK7MEa0r + uDdpDDtjutZpJBPXHvhN20L6 + KbkskBqEtrWYDV9YiZEVzC3tNZ / LQQNveA0pq + X + tl70vac5IUqfI ="
data = {
"params": params,
"encSecKey": encSecKey}
name_id = url.split('=')[1]
target_url = "http://music.163.com/weapi/v1/resource/comments/R_SO_4_{}?csrf_token=".format(name_id)
res = requests.post(target_url, headers=headers,data=data )
return res
def get_hot_comments(res):
comments_json = json.loads(res.text)
hot_comments = comments_json['hotComments']
with open('hot_comments111.txt', 'w', encoding='utf-8') as file:
for each in hot_comments:
file.write(each['user']['nickname'] + ':\n\n')
file.write(each['content'] + '\n')
file.write("---------------------------------------\n")
def find_data(res):
data = []
soup = bs4.BeautifulSoup(res.text, "html.parser")
content = soup.find_all("div", class_="cnt f-brk")
for each in content:
data.append(each.text)
return data
def main():
url = input("请输入链接地址:")
res = open_url(url)
get_hot_comments(res)
if __name__ == '__main__':
main()
|
|