初始方法TrendingUsersFullDeatils()不是在类中工作,而是在何处运行。计数被替换为数字。然而,当我创建一个类并传递一个整数时,我会得到一个属性错误,如下所示:
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)为了将整数传递给方法,我需要对类进行哪些修改,因为我已经在网上查看过了,而且由于某些原因,解决方案与我的不匹配。
以下代码在导入到代码中时将无法工作,因为需要安装必要的模块并从git存储库中检索。
发布于 2022-01-05 23:14:02
您还没有初始化对象(尚未调用init方法)。另外,您要将10作为参数传递给TrendingUsersFullDeatils方法,其中唯一的参数是self。这就是为什么它试图在整数中获得“计数”字段的原因。试试这个:
TikTokWebScraper(10).TrendingUsersFullDeatils()https://stackoverflow.com/questions/70600613
复制相似问题