Python 抓取本地加载的图像

Python 抓取本地加载的图像,python,web,web-scraping,urllib,Python,Web,Web Scraping,Urllib,我正在学习BeautifulSoup,在试图抓取从本地目录上传的图像时遇到了一个问题。我看到的错误是: ValueError: unknown url type: 'images/ixa2.png' 我假设图像是从本地目录加载的,而不是通过URL托管的。这是我检查试图刮伤的元件时的样子: <img width="200" align="left" hspace="0" src="ixa/cards/axisofmortality.jpg"> 您正在尝试从不完整的url下载图像 我

我正在学习BeautifulSoup,在试图抓取从本地目录上传的图像时遇到了一个问题。我看到的错误是:

ValueError: unknown url type: 'images/ixa2.png'
我假设图像是从本地目录加载的,而不是通过URL托管的。这是我检查试图刮伤的元件时的样子:

<img width="200" align="left" hspace="0" src="ixa/cards/axisofmortality.jpg">

您正在尝试从不完整的url下载图像

我的建议是这样的:

def get_images(url):
    soup = make_soup(url)
    images = [img for img in soup.findAll('img')]
    print (str(len(images)) + "images found.")
    print('Downloading images to current working directory.')
    #compile our unicode list of image links
    image_links = [each.get('src') for each in images]
    for each in image_links:
        filename=each.split('/')[-1]
        urllib.request.urlretrieve('http://mythicspoiler.com/' + each, filename) # <---
    return image_links
def get_图像(url):
汤=制作汤(url)
images=[img代表汤中的img.findAll('img')]
打印(str(len(图像))+“找到图像”。)
打印('将图像下载到当前工作目录')
#编译我们的unicode图像链接列表
图像链接=[each.get('src'),用于图像中的每一个]
对于每个in-image_链接:
filename=each.split('/')[-1]
urllib.request.urlretrieve('http://mythicspoiler.com/“+每个,文件名)#
def get_images(url):
    soup = make_soup(url)
    images = [img for img in soup.findAll('img')]
    print (str(len(images)) + "images found.")
    print('Downloading images to current working directory.')
    #compile our unicode list of image links
    image_links = [each.get('src') for each in images]
    for each in image_links:
        filename=each.split('/')[-1]
        urllib.request.urlretrieve('http://mythicspoiler.com/' + each, filename) # <---
    return image_links