Created
July 6, 2014 05:10
-
-
Save JonCooperWorks/4693d33ce811c48d035e to your computer and use it in GitHub Desktop.
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
"""Gets a list of links and prints the titles as the text for a hyperlink. | |
USAGE: python links.py <link1> <link2> ... <linkN> | |
Loops through a list of links and gets each one, parsing out the title of | |
the page, and using that as the link text. | |
""" | |
import sys | |
from pyquery import PyQuery | |
import requests | |
def main(): | |
urls = sys.argv[1:] | |
for url in urls: | |
response = requests.get(url) | |
if response.status_code != 200: | |
continue | |
d = PyQuery(response.text) | |
title = d('title').text() | |
print '<a href={url}>{title}</a>'.format(**locals()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment