如何修复孪生错误 "CRITICAL:root:twint.get:User:replace() argument 2 must be str, not None"
How to fix twint error "CRITICAL:root:twint.get:User:replace() argument 2 must be str, not None"
我正在尝试使用 twint 模块从 Twitter 获取一些信息,尤其是 bio。代码示例工作得很好:
import twint
c = twint.Config()
c.Username = "twitter"
twint.run.Lookup(c)
产量
783214 | Twitter | @Twitter | Private: 0 | Verified: 1 | Bio: What’s happening?! | Location: Everywhere | Url: https://about.twitter.com/ | Joined: 20 Feb 2007 6:35 AM | Tweets: 10816 | Following: 140 | Followers: 56328970 | Likes: 5960 | Media: 1932 | Avatar: https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png
事实是,我只需要生物数据。根据站点,您可以使用
c.Format = 'bio: {bio}'
不幸的是,这会产生
CRITICAL:root:twint.get:User:replace() argument 2 must be str, not None
我认为这可能是由于以下代码行(来自 here):
output += output.replace("{bio}", u.bio)
u.bio 值赋值 here:
u.bio = card(ur, "bio")
当我们的类型是 "bio" 时,卡片函数执行以下操作:
if _type == "bio":
try:
ret = ur.find("p", "ProfileHeaderCard-bio u-dir").text.replace("\n", " ")
except:
ret = None
我认为问题可能出在第二部分,其中一个值被分配给 u.bio,甚至没有被调用或由于某种原因返回 None。不幸的是,我不知道如何解决这个问题或调用该函数。
我之前用不同的函数遇到过类似的问题,twint.run.Following(c),但能够通过不设置 c.User_full = true
来解决它
有人能帮帮我吗?
格式应为
c.Format = "{bio}"
如果你想要多个字段
c.Format = "{bio} | {name}"
我发现您的速率限制为 250 个项目,然后阻止程序下降,您需要等待几分钟才能解除。
我正在尝试使用 twint 模块从 Twitter 获取一些信息,尤其是 bio。代码示例工作得很好:
import twint
c = twint.Config()
c.Username = "twitter"
twint.run.Lookup(c)
产量
783214 | Twitter | @Twitter | Private: 0 | Verified: 1 | Bio: What’s happening?! | Location: Everywhere | Url: https://about.twitter.com/ | Joined: 20 Feb 2007 6:35 AM | Tweets: 10816 | Following: 140 | Followers: 56328970 | Likes: 5960 | Media: 1932 | Avatar: https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png
事实是,我只需要生物数据。根据站点,您可以使用
c.Format = 'bio: {bio}'
不幸的是,这会产生
CRITICAL:root:twint.get:User:replace() argument 2 must be str, not None
我认为这可能是由于以下代码行(来自 here):
output += output.replace("{bio}", u.bio)
u.bio 值赋值 here:
u.bio = card(ur, "bio")
当我们的类型是 "bio" 时,卡片函数执行以下操作:
if _type == "bio":
try:
ret = ur.find("p", "ProfileHeaderCard-bio u-dir").text.replace("\n", " ")
except:
ret = None
我认为问题可能出在第二部分,其中一个值被分配给 u.bio,甚至没有被调用或由于某种原因返回 None。不幸的是,我不知道如何解决这个问题或调用该函数。
我之前用不同的函数遇到过类似的问题,twint.run.Following(c),但能够通过不设置 c.User_full = true
来解决它有人能帮帮我吗?
格式应为
c.Format = "{bio}"
如果你想要多个字段
c.Format = "{bio} | {name}"
我发现您的速率限制为 250 个项目,然后阻止程序下降,您需要等待几分钟才能解除。