使用Python,如何从Google搜索中获取链接的描述性文本?

使用Python,如何从Google搜索中获取链接的描述性文本?,python,selenium-webdriver,beautifulsoup,Python,Selenium Webdriver,Beautifulsoup,在python3中,我有一个脚本来抓取Google搜索的第一个屏幕: from bs4 import BeautifulSoup from selenium import webdriver from selenium.common.exceptions import NoAlertPresentException from selenium.webdriver.support.select import Select nome = '"ALDEANNO CAMPOS"' nome = nom

在python3中,我有一个脚本来抓取Google搜索的第一个屏幕:

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.select import Select

nome = '"ALDEANNO CAMPOS"'
nome = nome.replace(' ', '+')
cargo = 'DEPUTADO FEDERAL'

busca = f'https://www.google.com.br/search?q={nome}+{cargo}+ditadura'

profile = webdriver.FirefoxProfile()
browser = webdriver.Firefox(profile)

browser.get(busca)

html = browser.page_source
soup = BeautifulSoup(html, "html.parser")
browser.close()

page = soup.find_all("div", {"class": "rc"})

for link in page:
    href = link.find("a")['href']
    texto = link.find("a").text
    print(href)
    print(texto)
    print("---------------")
该程序显示或捕获href链接和链接的描述性文本,即页面名称。但我还想提取谷歌搜索链接下面的短语

例如,本页上的文本:

2018年8月24日-Purfl完成CordDato AO货物DeDututo联邦AddiaNo CAMPOS KOPOS COLCORE PELO PRP NAS EL EI Couses 2018没有PAARA.

巴西联邦政府官员和政府官员的关系符合。。。。坎波斯·科斯塔雷戈·累西腓,PE,PTB-PE 1962

弗朗西斯科·卢伊斯·达席尔瓦·坎波斯·多雷斯·多雷斯·多雷斯·多雷斯·多雷斯·多雷斯·多雷斯,1891年11月18日-贝洛·奥里藏特。。。Em 1921年弗朗西斯科·坎波斯(Francisco Campos foi eleito)担任联邦公共关系部部长。。。阿玛达斯在1937年11月成立了一家名为“阿玛达斯”的公司,该公司的筹备工作正在进行中

等等

请问,有人知道我怎样才能捕捉到链接下面的这篇最终文本吗

名称为CORONEL FERES的示例-打印链接-无法显示html代码

PSL Itapema-立柱|面bookhttps://www.facebook.com/PSLitapema17/posts/1638801189535968General 阿皮亚-卡迪达(Mourão apoia o pré-cadidato)是一个联邦代表团。Confira:37个视图。。。。Háuma ditadura sileniosa que não podemos permitir。我的天哪!
您只需要将其添加到循环中,请参见下面的代码

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.select import Select

nome = '"ALDEANNO CAMPOS"'
nome = nome.replace(' ', '+')
cargo = 'DEPUTADO FEDERAL'

busca = f'https://www.google.com.br/search?q={nome}+{cargo}+ditadura'

profile = webdriver.FirefoxProfile()
browser = webdriver.Firefox(profile)

browser.get(busca)

html = browser.page_source
soup = BeautifulSoup(html, "html.parser")
browser.close()

page = soup.find_all("div", {"class": "rc"})

for link in page:
    href = link.find("a")['href']
    texto = link.find("a").text
    body = link.find('span', attrs={'class': 'st'}).text
    print(href)
    print(texto)
    print(body)
    print("---------------")