如何在python中获取类似Google的url摘录 [英] How to get Google like url excerpts in python

查看:22
本文介绍了如何在python中获取类似Google的url摘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写过这样的代码:

#pip3 install google 
from googlesearch import search

query = 'java'


for i in search(query,        # The query you want to run
                tld = 'com',  # The top level domain
                lang = 'en',  # The language
                num = 10,     # Number of results per page
                start = 0,    # First result to retrieve
                stop = None,  # Last result to retrieve
                pause = 0,  # Lapse between HTTP requests
                safe = 'high'

               ):
    print(i)

在上面,我只是获取了 url 链接.我怎样才能为每个网址获得类似谷歌的摘录.就像附加的

in the above, I am simply getting the url link. How can I get google like excerpts for each url. Like the attached

推荐答案

我不认为可以用包来做,但是如果你在 python 上使用 requests 模块和一些 web抓取库 (beautifulsoup),您可以使用 HTML 标记 ()

I don't think it is possible to do it with the package BUT if you use the requests module on python with some web scraping libraries (beautifulsoup) you can get those descriptions with the HTML tag (<meta name="description" content="google description">)

这篇关于如何在python中获取类似Google的url摘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆