from detail_video import video_bvid
时间: 2024-06-21 13:03:30 浏览: 11
从`detail_video.py`模块导入`video_bvid`这个变量或函数的具体实现依赖于`detail_video.py`文件的内容。通常情况下,`video_bvid`可能是表示一个视频的唯一标识符,可能是一个B站视频的BV(Bilibili Video)ID。
假设`detail_video.py`中有一个函数或变量定义如下:
```python
# detail_video.py
def get_video_bvid():
return "BV号或其他视频ID"
# 或者
video_bvid = "BV号或其他视频ID"
```
你可以这样使用它:
```python
from detail_video import video_bvid
# 调用函数获取视频ID
bvid = video_bvid.get_video_bvid()
# 或者直接使用预定义的变量
bvid = video_bvid
```
请注意,这只是一个示例,实际的代码可能会根据`detail_video.py`文件的设计有所不同。如果你需要访问具体的视频详情,可能还需要调用其他相关的方法或属性。
相关问题
使用bat从{"media_type":2,"has_dash_audio":true,"is_completed":true,"total_bytes":54528541,"downloaded_bytes":54528541,"title":"【稚雨】宇宙 ૮ ´͈ ᗜ `͈ ა♡|ユニバース","type_tag":"112","cover":"http:\/\/i0.hdslb.com\/bfs\/archive\/aacd3a3a3397a4ca7426ff9ac237d57bd5ea5b6d.jpg","video_quality":112,"prefered_video_quality":112,"guessed_total_bytes":0,"total_time_milli":252543,"danmaku_count":33,"time_update_stamp":1689402493484,"time_create_stamp":1689402474935,"can_play_in_advance":true,"interrupt_transform_temp_file":false,"quality_pithy_description":"1080P","quality_superscript":"高码率","cache_version_code":7370300,"preferred_audio_quality":0,"audio_quality":0,"avid":870875619,"spid":0,"seasion_id":0,"bvid":"BV15V4y1b7Xv","owner_id":344270893,"owner_name":"稚雨才不是至于","owner_avatar":"https:\/\/i1.hdslb.com\/bfs\/face\/a3175ec8b252285ff802beedd8fe099016b90ea5.jpg","page_data":{"cid":1196836330,"page":1,"from":"vupload","part":"宇宙","link":"","vid":"","has_alias":false,"tid":20,"width":1920,"height":1080,"rotate":0,"download_title":"视频已缓存完成","download_subtitle":"【稚雨】宇宙 ૮ ´͈ ᗜ `͈ ა♡|ユニバース 宇宙"}}之中提取题目
你可以使用 Batch 脚本中的字符串操作来提取 JSON 数据中的 `title` 字段。下面是一个示例脚本:
```batch
@echo off
setlocal enabledelayedexpansion
set "json={"media_type":2,"has_dash_audio":true,"is_completed":true,"total_bytes":54528541,"downloaded_bytes":54528541,"title":"【稚雨】宇宙 ૮ ´͈ ᗜ `͈ ა♡|ユニバース","type_tag":"112","cover":"http:\/\/i0.hdslb.com\/bfs\/archive\/aacd3a3a3397a4ca7426ff9ac237d57bd5ea5b6d.jpg","video_quality":112,"preferred_video_quality":112,"guessed_total_bytes":0,"total_time_milli":252543,"danmaku_count":33,"time_update_stamp":1689402493484,"time_create_stamp":1689402474935,"can_play_in_advance":true,"interrupt_transform_temp_file":false,"quality_pithy_description":"1080P","quality_superscript":"高码率","cache_version_code":7370300,"preferred_audio_quality":0,"audio_quality":0,"avid":870875619,"spid":0,"seasion_id":0,"bvid":"BV15V4y1b7Xv","owner_id":344270893,"owner_name":"稚雨才不是至于","owner_avatar":"https:\/\/i1.hdslb.com\/bfs\/face\/a3175ec8b252285ff802beedd8fe099016b90ea5.jpg","page_data":{"cid":1196836330,"page":1,"from":"vupload","part":"宇宙","link":"","vid":"","has_alias":false,"tid":20,"width":1920,"height":1080,"rotate":0,"download_title":"视频已缓存完成","download_subtitle":"【稚雨】宇宙 ૮ ´͈ ᗜ `͈ ა♡|ユニバース 宇宙"}}"
set "title=!json:*\"title\":\"=!"
set "title=!title:~0,-1!"
echo %title%
```
在上述脚本中,我将 JSON 数据存储在 `json` 变量中。然后使用字符串操作来提取 `title` 字段。
首先,使用 `set "title=!json:*\"title\":\"=!"` 将 `title` 变量设置为从 JSON 数据中删除 `title":"` 后的内容。
然后,使用 `set "title=!title:~0,-1!"` 去除最后一个字符(JSON 数据中的双引号),得到最终的题目内容。
请注意,脚本中的字符串操作可能需要根据你的实际情况进行修改。
python爬取b站评论_用python 抓取B站视频评论,制作词云
好的,很高兴回答您的问题!
首先,我们需要安装一些必要的库,如requests、BeautifulSoup、jieba、wordcloud等。你可以使用以下命令进行安装:
```
pip install requests
pip install BeautifulSoup4
pip install jieba
pip install wordcloud
```
接下来,我们需要先获取视频的av号(或者BV号),然后通过B站的API接口来获取评论数据。代码如下:
```python
import requests
import json
# 获取B站视频评论
def get_bilibili_comment(aid):
url = "https://api.bilibili.com/x/v2/reply?pn={}&type=1&oid={}&sort=2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
comments = []
for i in range(1, 6): # 抓取前5页评论
response = requests.get(url.format(i, aid), headers=headers)
data = json.loads(response.text)
for comment in data["data"]["replies"]:
comments.append(comment["content"]["message"])
return comments
# 获取B站视频的av号
def get_bilibili_av(bv):
url = "https://api.bilibili.com/x/web-interface/view?bvid={}"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
response = requests.get(url.format(bv), headers=headers)
data = json.loads(response.text)
return data["data"]["aid"]
```
接着,我们需要使用jieba库对评论内容进行分词,并将分词结果存储到一个列表中。代码如下:
```python
import jieba
# 分词
def cut_words(comments):
words = []
for comment in comments:
words += jieba.lcut(comment)
return words
```
最后,我们可以使用wordcloud库来制作词云图。代码如下:
```python
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# 制作词云图
def make_wordcloud(words):
text = " ".join(words)
wc = WordCloud(background_color="white", max_words=200, font_path="msyh.ttc")
wc.generate(text)
plt.imshow(wc)
plt.axis("off")
plt.show()
```
完整代码如下:
```python
import requests
import json
import jieba
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# 获取B站视频评论
def get_bilibili_comment(aid):
url = "https://api.bilibili.com/x/v2/reply?pn={}&type=1&oid={}&sort=2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
comments = []
for i in range(1, 6): # 抓取前5页评论
response = requests.get(url.format(i, aid), headers=headers)
data = json.loads(response.text)
for comment in data["data"]["replies"]:
comments.append(comment["content"]["message"])
return comments
# 获取B站视频的av号
def get_bilibili_av(bv):
url = "https://api.bilibili.com/x/web-interface/view?bvid={}"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
response = requests.get(url.format(bv), headers=headers)
data = json.loads(response.text)
return data["data"]["aid"]
# 分词
def cut_words(comments):
words = []
for comment in comments:
words += jieba.lcut(comment)
return words
# 制作词云图
def make_wordcloud(words):
text = " ".join(words)
wc = WordCloud(background_color="white", max_words=200, font_path="msyh.ttc")
wc.generate(text)
plt.imshow(wc)
plt.axis("off")
plt.show()
if __name__ == "__main__":
bv = input("请输入B站视频的BV号:")
aid = get_bilibili_av(bv)
comments = get_bilibili_comment(aid)
words = cut_words(comments)
make_wordcloud(words)
```
这样,我们就可以使用Python来抓取B站视频评论,并制作词云图了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)