forked from delta4d/douban-album-dl
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ein Verne <einverne@gmail.com>
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding:utf-8 -*- | ||
import os | ||
|
||
import requests | ||
|
||
from douban.celebrity import Celebrity | ||
|
||
|
||
def get_celebrity(celebrity, path): | ||
idx = 0 | ||
if not os.path.exists(path): | ||
os.mkdir(path) | ||
os.chdir(path) | ||
for refer, photo_url in celebrity.photos(): | ||
name = os.path.basename(photo_url) | ||
if os.path.exists(name): | ||
print("pic {} exist skip".format(name)) | ||
continue | ||
print("{}: saving {}".format(idx, name)) | ||
headers = { | ||
"Referer": refer, | ||
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36" | ||
} | ||
r = requests.get(photo_url, headers=headers, stream=True) | ||
with open(name, "wb") as f: | ||
f.write(r.content) | ||
idx += 1 | ||
print("saving celebrity photo to {}".format(path)) | ||
|
||
|
||
if __name__ == "__main__": | ||
celebrity_id = "1335340" | ||
celebrity = Celebrity(celebrity_id) | ||
path = os.path.expanduser("~") + "/Pictures/celebrity/" + celebrity_id | ||
get_celebrity(celebrity, path) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding:utf-8 -*- | ||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
class Celebrity: | ||
BASE_URL = "https://movie.douban.com/celebrity/{}/photos/" | ||
|
||
def __init__(self, celebrity_id): | ||
self.url = Celebrity.BASE_URL.format(celebrity_id) | ||
|
||
def photos(self): | ||
start = 0 | ||
while True: | ||
next_photos = self.__photos(start) | ||
step = len(next_photos) | ||
if 0 == step: | ||
break | ||
for photo in next_photos: | ||
# https://img3.doubanio.com/view/photo/thumb/public/p2156276775.jpg | ||
# https://img3.doubanio.com/view/photo/raw/public/p2156276775.jpg | ||
# https://img3.doubanio.com/view/photo/photo/public/p2156276775.webp | ||
yield photo.a['href'], photo.img['src'].replace("photo/thumb", "photo/raw") | ||
start += step | ||
|
||
def __photos(self, start): | ||
params = { | ||
"type": "C", | ||
"start": start, | ||
"sortby": "vote", | ||
"size": "a", | ||
"subtype": "a" | ||
} | ||
r = requests.get(self.url, params=params) | ||
soup = BeautifulSoup(r.text, "html.parser") | ||
return soup.find_all("div", class_="cover") |