from googlesearch import search
import requests
from bs4 import BeautifulSoup
def search_google(query):
url = list(search(query, num=1))[0]
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
result = soup.get_text()
return result
while True:
query = input("What would you like to search for on Google? ")
result = search_google(query)
print(result)
1条答案
按热度按时间weylhg0b1#
安装一些工具
使用beautifulsoup从HTML响应中提取文本
修剪响应,仅显示几个句子
我会留给你,因为展示多少是你个人的选择。