Created
November 2, 2016 08:51
-
-
Save samkeeleyong/3da9b6001904dbf3819f176b14a9c1d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# grab files from http://music.forunesia.com/2015/05/love-live-school-idol-project-complete.html?m=1 | |
import requests | |
from lxml import html | |
from clint.textui import progress | |
import urllib | |
def mainProcess(): | |
response = requests.get('http://music.forunesia.com/2015/05/love-live-school-idol-project-complete.html?m=1') | |
tree = html.fromstring(response.content) | |
anchor_tags = tree.xpath("//a[contains(text(), '[Direct]')]") | |
for a in anchor_tags: | |
href = a.attrib['href'] | |
if href.endswith('rar'): | |
path = urllib.unquote(href.rsplit('/', 1)[-1]).decode('utf-8') | |
r = requests.get(href, stream=True) | |
with open(path, 'wb') as f: | |
total_length = int(r.headers.get('content-length')) | |
for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): | |
if chunk: | |
f.write(chunk) | |
f.flush() | |
mainProcess() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment