google.py 文件源码

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

项目:pyconjpbot 作者: pyconjp 项目源码 文件源码
def google_image(message, keywords):
    """
    google ????????????

    https://github.com/llimllib/limbo/blob/master/limbo/plugins/image.py
    """

    query = quote(keywords)
    searchurl = "https://www.google.com/search?tbm=isch&q={0}".format(query)

    # this is an old iphone user agent. Seems to make google return good results.
    useragent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Versio  n/4.0.5 Mobile/8A293 Safari/6531.22.7"

    result = requests.get(searchurl, headers={"User-agent": useragent}).text
    images = list(map(unescape, re.findall(r"var u='(.*?)'", result)))

    if images:
        botsend(message, choice(images))
    else:
        botsend(message, "`{}` ???????????????".format(keywords))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号