Skip to content

Instantly share code, notes, and snippets.

@rsadwick
Created October 13, 2014 12:54
Show Gist options
  • Save rsadwick/47c188dc2df1d026896d to your computer and use it in GitHub Desktop.
Save rsadwick/47c188dc2df1d026896d to your computer and use it in GitHub Desktop.
snags related hash tags based on query
import urllib2
from bs4 import BeautifulSoup
site_url = 'https://ritetag.com/best-hashtags-for/'
hash_tag = raw_input()
response = urllib2.urlopen(site_url + hash_tag)
html = response.read()
soup = BeautifulSoup(html)
def match_class(target):
def do_match(tag):
classes = tag.get('class', [])
return all(c in classes for c in target)
return do_match
tags = soup.find_all(match_class(["tag"]))
for spans in tags:
print spans.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment