gpt4 book ai didi

python - Scraper Python和YouTube API

转载 作者:行者123 更新时间:2023-12-03 05:53:03 25 4
gpt4 key购买 nike

想要在某些 channel 统计数据中删除youtube,并了解其工作原理。并且比作csv作以下分析。使用this video创建和学习。

我有2个文件:
main.py,youtube_statistics

main.py

from youtube_statistics import YTstats

API_KEY = "xxx"
channel_id = "xxx"

yt = YTstats(API_KEY, channel_id)
yt.get_channel_statistics()

youtube_statistics.py
class YTstats:
def_init_(self, api_key, channel_id)
self.api_key = api_key
self.channel_id = channel_id
self.channel_statistics = None


def get_channel_statistics(self):
url = f'https://www.googleapis.com/youtube/v3/channels?part=statistics&id={self.channel_id}&key={self.api_key}'
print(url)

这不是全部代码,而是尝试运行主要的错误:
Traceback (most recent call last):
File "D:/!Python/YouTube API/main.py", line 1, in <module>
from youtube_statistics import YTstats
File "D:\!Python\YouTube API\youtube_statistics.py", line 1, in <module>
class YTstats:
File "D:\!Python\YouTube API\youtube_statistics.py", line 2, in YTstats
def_init_(self, api_key, channel_id)
NameError: name 'def_init_' is not defined

怎么了,怎么解决?在视频上一切正常。

谢谢。

最佳答案

在python中,缩进很重要。您的youtube_statistics.py文件缩进了错误的位置。特别是类初始化被声明为错误。这是固定版本:

class YTstats:
def __init__(self, api_key, channel_id):
self.api_key = api_key
self.channel_id = channel_id
self.channel_statistics = None


def get_channel_statistics(self):
url = f'https://www.googleapis.com/youtube/v3/channels?part=statistics&id={self.channel_id}&key={self.api_key}'
print(url)

关于python - Scraper Python和YouTube API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61715852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com