我正在尝试遍历 subreddits,但想忽略顶部的置顶帖子。我能够打印前 5 个帖子,不幸的是包括即时贴。尝试跳过这些的各种 pythonic 方法都失败了。下面是我的代码的两个不同示例。
subreddit = reddit.subreddit(sub)
for submission in subreddit.hot(limit=5):
# If we haven't replied to this post before
if submission.id not in posts_replied_to:
##FOOD
if subreddit == 'food':
if 'pLEASE SEE' in submission.title:
pass
if "please vote" in submission.title:
pass
else:
print(submission.title)
if re.search("please vote", submission.title, re.IGNORECASE):
pass
else:
print(submission.title)
我注意到文档中有一个粘性标签,但不确定如何使用它。感谢您的帮助。
请您参考如下方法:
粘附的提交有一个 sticked 属性,该属性的计算结果为 True。将以下内容添加到您的循环中,您应该可以开始了。
if submission.stickied:
continue
一般来说,我建议检查您正在使用的对象的可用属性,看看是否有可用的东西。请参阅:Determine Available Attributes of an Object
