python使用urllib2模块获取gravatar头像实例
时间:2022-12-11 03:16:36
Gravatar注册地址: https://en.gravatar.com/
"""`Gravatar <https://en.gravatar.com/site/implement/>`_"""
# import code for encoding urls and generating md5 hashes
import urllib2, hashlib
# Make response slow if verify whether default avatar or not.
# So let js do it, see `/static/js/article.js`.
def gravatar_url(email, size=40, verify_default=False):
"""Construct the gravatar url."""
gravatar_url = ''.join(['http://www.gravatar.com/avatar/',
hashlib.md5(email.lower()).hexdigest(), '?s=%d' % size])
# if default return None
if (verify_default):
gravatar_url += '&d=404'
try:
urllib2.urlopen(gravatar_url)
except urllib2.URLError, e:
return None
return gravatar_url
if __name__ == '__main__':
import webbrowser as wb
for email in ['xxx@gmail.com']:
url = gravatar_url(email)
print(url)
if url:
wb.open(url)
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL中SQL Mode的查看与设置详解
python 调整图片亮度的示例
![](https://img.aspxhome.com/file/2023/7/95507_0s.png)
Python利用3D引擎写一个Pong游戏
![](https://img.aspxhome.com/file/2023/4/131704_0s.png)
asp版FCKEditor编辑器的用法
Flask框架实现的前端RSA加密与后端Python解密功能详解
![](https://img.aspxhome.com/file/2023/7/89277_0s.jpg)
PyCharm取消波浪线、下划线和中划线的实现
![](https://img.aspxhome.com/file/2023/4/117974_0s.png)
Python标准模块--ContextManager上下文管理器的具体用法
Python爬虫小技巧之伪造随机的User-Agent
python应用Axes3D绘图(批量梯度下降算法)
![](https://img.aspxhome.com/file/2023/8/90638_0s.jpg)
详解JavaScript 高阶函数
Python中安装库的常用方法介绍
![](https://img.aspxhome.com/file/2023/8/85038_0s.png)
Javascript优化技巧(文件瘦身篇)
Python eval的常见错误封装及利用原理详解
解析:在SQL Server下数据库链接的使用
怎样管理好css样式
Python存储读取HDF5文件代码解析
Python中的X[:,0]、X[:,1]、X[:,:,0]、X[:,:,1]、X[:,m:n]和X[:,:,m:n]
通过python绘制华强买瓜的字符画视频的步骤详解
![](https://img.aspxhome.com/file/2023/3/118663_0s.jpg)
go语言中切片的长度和容量的区别
![](https://img.aspxhome.com/file/2023/8/134218_0s.png)