diff --git a/102201214 许莎莎.py b/102201214 许莎莎.py index e345a1c..fdeddac 100644 --- a/102201214 许莎莎.py +++ b/102201214 许莎莎.py @@ -47,12 +47,10 @@ def seek_api_urls(html_data): def get_api_urls(url): response = requests.get(url, headers=headers) if response.status_code == 200: - # 若请求成功则查找api链接 html_data=response.text api_urls=seek_api_urls(html_data) return api_urls else: - # 返回一个空列表作为默认值 return [] # 获取视频接口函数 @@ -109,21 +107,15 @@ def vedio_transform_port(url): port_urls.add(port_url.replace("bilibili.com", "ibilibili.com")) for page in range(1,8): - # 获取视频链接 vedio_urls=get_urls(page) - # 创建接口链接列表 port_urls=set() for vedio_url in vedio_urls: - # 将视频链接转换成接口链接 port_url = vedio_transform_port(vedio_url) - # 循环访问接口 + for url in port_urls: - #获取弹幕链接 api_urls=get_api_urls(url) - # 检查列表是否为空 if api_urls: - #不为空,则将获取弹幕链接 api_url = api_urls[0] html_data = get_html(api_url) soup = BeautifulSoup(html_data, 'html.parser')