[Python] How to search multiple keywords in all subreddits in Reddit using PRAW in Python

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to search a list of multiple key words in Reddit posts in all subreddits. At the moment my dataframe is showing just results for the last word in the keyword_list list which is 'maritime history'. Does anyone know how I can get this to search all of the words?

    # Creating keyword list
    keyword_list = ['maritime heritage', 'shipwreck', 'shipwrecks', 'coastal archeaology', 'maritime archaeology',
    'maritime ecologies', 'marine archeaology', 'marine heritage', 'cultural marine heritage', 'marine culutral haritage', 'maritime history']

    # Searching in all subreddits
    all = reddit.subreddit("all")
    df = pd.DataFrame() # creating dataframe for displaying scraped data

    # creating lists for storing scraped data
    titles=[]
    scores=[]
    ids=[]

    # looping over posts and scraping it
    for submission in all.search(keyword_list, limit=None):
    titles.append(submission.title)
    scores.append(submission.score) #upvotes
    ids.append(submission.id)


    df['Title'] = titles
    df['Id'] = ids
    df['Upvotes'] = scores #upvotes

    print(df.shape)
    df.head(10)

    Continue reading...

Compartilhe esta Página