Last active
September 30, 2018 13:28
-
-
Save yurivictor/7798679 to your computer and use it in GitHub Desktop.
Scrape your @Medium post links into HTML list, if you want to add them to your site, or whatever
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
import requests | |
from pyquery import PyQuery as pq | |
USERNAME = 'ev' # change to your username | |
def get_medium_posts(): | |
url = 'http://medium.com/@' + USERNAME + '/latest' | |
request = requests.get( url ) | |
html = request.content | |
return pq( html )( '.post-item-title h3 a' ) | |
def show_medium_posts(): | |
posts = get_medium_posts() | |
html = '<ul>' | |
for post in posts: | |
url = 'http://medium.com' + post.attrib['href'] | |
headline = pq( post ).text() | |
html += '<li><a href="' + url + '">' + headline + '</a></li>' | |
html += '</ul>' | |
print html | |
show_medium_posts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment