Skip to content

Instantly share code, notes, and snippets.

@pilate pilate/urltitle.py
Last active Dec 22, 2015

Embed
What would you like to do?
from HTMLParser import HTMLParser
import requests
import re
url_regex = "(https?:\/\/[^ ]+)"
class TitleParser(HTMLParser):
istitle = False
def handle_starttag(self, tag, attrs):
if tag == "title":
self.istitle = True
def handle_data(self, data):
if self.istitle:
self.title = data
self.istitle = False
def run(data, settings):
re_test = re.search(url_regex, data['payload'])
if re_test:
url = re_test.group(0)
r = requests.get(url)
parser = TitleParser()
parser.feed(r.text)
return parser.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.