Created
October 23, 2019 18:14
-
-
Save teemuy/81b1562db324f86acb024d00c2fe3564 to your computer and use it in GitHub Desktop.
Fetch HTML title given page URL, using requests and lxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Fetch HTML title for URL""" | |
import sys | |
import requests | |
import lxml.html as html | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('Fetches HTML title for given URL.\n\nUsage: %s <URL>' % sys.argv[0]) | |
sys.exit(1) | |
req = requests.get(sys.argv[1]) | |
doc = html.fromstring(req.content) | |
title = doc.xpath('head/title')[0] | |
print(title.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment