首页 > 解决方案 > 如何在 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 链接。我怎样才能为每个 url 获得类似谷歌的摘录。和附件一样在此处输入图像描述

标签: pythonweb-scrapingbeautifulsoup

解决方案


我认为使用包是不可能的,但是如果你requests在 python 上使用模块和一些网络抓取库(beautifulsoup<meta name="description" content="google description"> ),你可以使用 HTML 标签( )获取这些描述


推荐阅读