Python 如何使用Beauty soup从网站下载图像?

Python 如何使用Beauty soup从网站下载图像?,python,image,web-scraping,beautifulsoup,Python,Image,Web Scraping,Beautifulsoup,我想保存来自网站的图像,是否可以在Python中使用BeautifulSoup库。我们需要枕头图书馆吗?或者我们可以将它们转换成numpy数组,并使用open CV处理tem吗?在不提供任何细节的情况下,任何人都可以给出一个一般性的答案。但是是的,这是可能的 我想象你会使用beautifulsoup来提取图像的url,然后使用该url来提取并保存图像。比如: from PIL import Image import requests import bs4 url = 'some.site.co

我想保存来自网站的图像,是否可以在Python中使用BeautifulSoup库。我们需要枕头图书馆吗?或者我们可以将它们转换成numpy数组,并使用open CV处理tem吗?

在不提供任何细节的情况下,任何人都可以给出一个一般性的答案。但是是的,这是可能的

我想象你会使用beautifulsoup来提取图像的url,然后使用该url来提取并保存图像。比如:

from PIL import Image
import requests
import bs4

url = 'some.site.com'

response = requests.get(url)

soup = bs4.BeautifulSoup(response.text, 'html.parser')

image = soup.find('img')
image_url = image['src']


img = Image.open(requests.get(image_url, stream = True).raw)

img.save('image.jpg')
我觉得这很有用。