Fixed title plugin
This commit is contained in:
parent
00d80f0122
commit
cf377e1800
2 changed files with 9 additions and 8 deletions
19
plugins/title.py
Executable file
19
plugins/title.py
Executable file
|
@ -0,0 +1,19 @@
|
|||
from util import hook, http, urlnorm
|
||||
|
||||
|
||||
@hook.command
|
||||
def title(inp):
|
||||
"title <url> -- gets the title of a web page"
|
||||
url = urlnorm.normalize(inp.encode('utf-8'), assume_scheme="http")
|
||||
|
||||
try:
|
||||
page = http.get_html(url)
|
||||
except (http.HTTPError, http.URLError):
|
||||
return "Could not fetch page."
|
||||
|
||||
try:
|
||||
title = page.find(".//title").text
|
||||
except AttributeError:
|
||||
return "Could not find title."
|
||||
|
||||
return http.unescape(title)
|
Reference in a new issue