Skip to content

增加下载头像的功能 #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions zhihu.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,31 @@ def get_head_img_url(self, scale=4):
soup = self.soup
url = soup.find("img", class_="Avatar Avatar--l")["src"]
return url[:-5] + scale_name[scale] + url[-4:]

def download_head_img(self, head_url=None):
url = get_head_img_url()
r = requests.get(url)
user = get_user_id()
image_name = user + url[-4:]

if os.path.exists(os.path.join(os.getcwd(), 'Avatar')):
new_dir = raw_input(u'请输入想保存的路径名称')
os.mkdir(new_dir)
os.chdir(new_dir)
else:
os.mkdir('Avatar')
os.chdir('Avatar')

with open(image_name, 'wb') as image:
image.write(r.content)

if os.path.isfile(image_name):
Logging.success(u'Success Download the Avatar')
return True
else:
Logging.error(u'Error happened')
return False

def get_data_id(self):
"""
By yannisxu (https://github.com/yannisxu)
Expand Down