Last active
January 21, 2016 09:53
-
-
Save 6david9/806604180ead11e69883 to your computer and use it in GitHub Desktop.
wwdc2014 sessions download links
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 os.path | |
import requests | |
from lxml import etree | |
file_path = 'https://developer.apple.com/videos/wwdc/2014/' | |
sd_path = os.path.expanduser("~/Desktop/wwdc2014_sd.txt") | |
hd_path = os.path.expanduser("~/Desktop/wwdc2014_hd.txt") | |
pdf_path = os.path.expanduser("~/Desktop/wwdc2014_pdf.txt") | |
sd_file = open(sd_path, "w") | |
hd_file = open(hd_path, "w") | |
pdf_file = open(pdf_path, "w") | |
r = requests.get(file_path) | |
tree = etree.HTML(r.text) | |
sessions = tree.xpath("//li[@class='session']") | |
for session in sessions: | |
title = session.xpath("./ul/li[@class='title']/text()")[0] | |
links = session.xpath(".//p[@class='download']") | |
hd_url = session.xpath(".//a[contains(text(), 'HD')]/attribute::href") | |
sd_url = session.xpath(".//a[contains(text(), 'SD')]/attribute::href") | |
pdf_url = session.xpath(".//a[contains(text(), 'PDF')]/attribute::href") | |
hd_url = hd_url[0] if len(hd_url) > 0 else '' | |
sd_url = sd_url[0] if len(sd_url) > 0 else '' | |
pdf_url = pdf_url[0] if len(pdf_url) > 0 else '' | |
# hd_url = hd_url.replace(u"\xe2\x80\x99", "") | |
# sd_url = sd_url.replace(u"\xe2\x80\x99", "") | |
hd_file.write(hd_url + "\n") | |
sd_file.write(sd_url + "\n") | |
pdf_file.write(pdf_url + "\n") | |
print("\033[92m%s\033[0m\n\t%s\n\t%s\n\t%s\n" % (title, hd_url, sd_url, '')) | |
sd_file.close() | |
hd_file.close() | |
pdf_file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment