网站开发
·2025-01-25import requests
from bs4 import BeautifulSoup
# 定义Cookies
cookies = {
'kpf': 'PC_WEB',
'clientid': '3',
'did': 'web_15e57618aee182da54fc254185c51566',
'didv': '1736656847676',
'kpn': 'KUAISHOU_VISION',
}
# 定义Headers
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Referer': 'https://www.kuaishou.com/',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0',
'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
# 定义搜索参数
params = {
'searchKey': '励志',
}
# 目标URL
url = 'https://www.kuaishou.com/search'
# 发送GET请求
try:
response = requests.get(url, params=params, cookies=cookies, headers=headers)
response.raise_for_status() # 检查请求是否成功
html_content = response.text
# 使用BeautifulSoup解析HTML
soup = BeautifulSoup(html_content, 'html.parser')
# 根据快手的页面结构提取视频信息
# 这里需要根据实际的HTML结构进行调整
# 例如,假设每个视频在<div class="video-item">中
videos = soup.find_all('div', class_='video-item')
for video in videos:
title = video.find('a', class_='title').get_text(strip=True)
link = video.find('a', class_='title')['href']
author = video.find('a', class_='author').get_text(strip=True)
print(f"标题: {title}\n链接: https://www.kuaishou.com{link}\n作者: {author}\n")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP错误: {http_err}")
except Exception as err:
print(f"其他错误: {err}")
求分析 我运行是空的
1
0
分享
操作
评论
问答助学
相关内容
0个评论
全部评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
