BeautifulSoup:未找到连接适配器错误



我的目标是在谷歌上搜索指定的字符串,并从找到的url中保存图像。我一直在学习在线教程,但不断收到相同的InvalidSchema错误,不知道为什么。

from PIL import Image
from bs4 import BeautifulSoup
import requests
text= "animal+crossing"
html_page = requests.get("https://www.google.com/search?q="+text)
soup = BeautifulSoup(html_page.text, 'html.parser')
image = soup.find('img')
img_url = image['src']
img = Image.open(requests.get(img_url, stream = True).raw)
img.save('image.jpg')

在这一步中获取的图像url:img_url = image['src']实际上不是一个有效的url。这是我运行代码时看到的img_url的值:

data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==

最新更新