Skip to content

Instantly share code, notes, and snippets.

@DanNi0130
Created February 24, 2019 07:17
Show Gist options
  • Save DanNi0130/7dc0e17c83bc91e704ed97fd432ed7f0 to your computer and use it in GitHub Desktop.
Save DanNi0130/7dc0e17c83bc91e704ed97fd432ed7f0 to your computer and use it in GitHub Desktop.
def scrapethread(cleanthread): # We need to feed the thread data into the function
singlethreadlinksearch = re.compile(r'\<a class="storylink" href="(.+?)"\>')
singlethreadlink = singlethreadlinksearch.findall(str(cleanthread))
commenterIDsearch = re.compile(r'user\?id=(.+?)"')
commenterIDs = commenterIDsearch.findall(str(cleanthread))
try:
firstcommenter = commenterIDs[1] # If there are no commenters this will fail, so we wrap it in a try/except just in case
except:
firstcommenter = "No commenters"
return singlethreadlink, firstcommenter # Return the variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment