webman.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:WebMan 作者: flipflop97 项目源码 文件源码
def getShortcutIcon(pkgname):
    try:
        return getShortcutIcon.cache[pkgname]
    except AttributeError:
        getShortcutIcon.cache = {}
    except KeyError:
        try:
            packageUrl = parsePackage(getPackageInfo(pkgname))[3]
            pool = PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=where())
            pageRequest = pool.request('GET', packageUrl, timeout=3.0)
            pageContent = pageRequest.data
            pageSoup = BeautifulSoup(pageContent, 'html.parser')
            iconLink = pageSoup.find('link', rel='icon')['href']
            getShortcutIcon.cache[pkgname] = urljoin(packageUrl, iconLink)
        except:
            try:
                getShortcutIcon.cache[pkgname] = urljoin(packageUrl, '/favicon.ico')
            except:
                getShortcutIcon.cache[pkgname] = None

    return getShortcutIcon(pkgname)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号