AttributeError: 'int' object has no attribute 'count'
AttributeError: 'int' object has no attribute 'count'
初始方法 TrendingUsersFullDeatils() 在不在 class 中并且在 self 中工作。 count 代替了一个数字。
但是,当我创建一个 class 并传递一个整数时,我得到如下所示的属性错误:
tiktoks = tiktok_api.by_trending(count=self.count)
AttributeError: 'int' object has no attribute 'count'
代码:
from TikTokApi import TikTokApi
import json
tiktok_api = TikTokApi.get_instance()
tiktok_data = []
class TikTokWebScraper():
def __init__(self, count=0):
self.count = int(count)
def TrendingUsersFullDeatils(self):
tiktoks = tiktok_api.by_trending(count=self.count)
for tiktok in tiktoks:
tiktok_data.append({"Username": tiktok["author"]["uniqueId"],
"Follower Count": tiktok["authorStats"]["followerCount"],
"Id": tiktok["author"]["id"],
"uniqueID": tiktok["author"]["uniqueId"],
"Nickname": tiktok["author"]["nickname"],
"Verfied Status": tiktok["author"]["verified"],
"Private": tiktok["author"]["privateAccount"],
"Following Count": tiktok["authorStats"]["followingCount"],
"Follower Count": tiktok["authorStats"]["followerCount"],
"Heart Count": tiktok["authorStats"]["heartCount"],
"Video Count": tiktok["authorStats"]["videoCount"]})
f = open("tiktok.json", "w")
j = json.dumps(tiktok_data, indent= 4)
f.write(j)
f.close()
TikTokWebScraper.TrendingUsersFullDeatils(10)
我需要对 class 进行哪些修改才能将整数传递给该方法,正如我在网上查看的那样,由于某种原因,解决方案与我的不匹配。
以下代码在导入代码时将不起作用,因为需要安装必要的模块并从 git 存储库中检索。
您还没有初始化您的对象(还没有调用您的 init 方法)。此外,您将 10 作为参数传递给 TrendingUsersFullDeatils 方法,其中唯一的参数是 self。这就是它试图以整数形式获取 'count' 字段的原因。试试这个:
TikTokWebScraper(10).TrendingUsersFullDeatils()
初始方法 TrendingUsersFullDeatils() 在不在 class 中并且在 self 中工作。 count 代替了一个数字。 但是,当我创建一个 class 并传递一个整数时,我得到如下所示的属性错误:
tiktoks = tiktok_api.by_trending(count=self.count)
AttributeError: 'int' object has no attribute 'count'
代码:
from TikTokApi import TikTokApi
import json
tiktok_api = TikTokApi.get_instance()
tiktok_data = []
class TikTokWebScraper():
def __init__(self, count=0):
self.count = int(count)
def TrendingUsersFullDeatils(self):
tiktoks = tiktok_api.by_trending(count=self.count)
for tiktok in tiktoks:
tiktok_data.append({"Username": tiktok["author"]["uniqueId"],
"Follower Count": tiktok["authorStats"]["followerCount"],
"Id": tiktok["author"]["id"],
"uniqueID": tiktok["author"]["uniqueId"],
"Nickname": tiktok["author"]["nickname"],
"Verfied Status": tiktok["author"]["verified"],
"Private": tiktok["author"]["privateAccount"],
"Following Count": tiktok["authorStats"]["followingCount"],
"Follower Count": tiktok["authorStats"]["followerCount"],
"Heart Count": tiktok["authorStats"]["heartCount"],
"Video Count": tiktok["authorStats"]["videoCount"]})
f = open("tiktok.json", "w")
j = json.dumps(tiktok_data, indent= 4)
f.write(j)
f.close()
TikTokWebScraper.TrendingUsersFullDeatils(10)
我需要对 class 进行哪些修改才能将整数传递给该方法,正如我在网上查看的那样,由于某种原因,解决方案与我的不匹配。
以下代码在导入代码时将不起作用,因为需要安装必要的模块并从 git 存储库中检索。
您还没有初始化您的对象(还没有调用您的 init 方法)。此外,您将 10 作为参数传递给 TrendingUsersFullDeatils 方法,其中唯一的参数是 self。这就是它试图以整数形式获取 'count' 字段的原因。试试这个:
TikTokWebScraper(10).TrendingUsersFullDeatils()