我需要将此网站的图片保存到文件夹中:
http://www.photobirdireland.com/garden-birds.html
我尝试过使用导入操作系统
from lxml import html
from urllib.request import urlopen
from bs4 import BeautifulSoup as bs
class ImageScraper:
def __init__(self, url, download_path):
self.url = url
self.download_path = download_path
self.session = requests.Session()
def scrape_images(self):
html = urlopen(url)
bs4 = bs(html, 'html.parser')
images = bs4.find_all('img', {})
scraper = ImageScraper(url="http://www.photobirdireland.com/garden-birds.html")
scraper.scrape_images()
f = open('Users/Lu/Desktop/Images','wb') # folder
f.write(img)
f.close()
但我没有得到任何结果或错误
我很确定代码中有些东西不起作用
请你看一下,告诉我怎么了
这个
html = urlopen(url)
应该是html = urlopen(self.url)
编辑:您可以像这样获取URL
下一步就是找到如何下载它们
尝试以下代码下载图像。使用
urlretrieve
将图像src值下载到位置您的代码不完整,在
images = bs4.find_all('img', {})
示例
完整的代码应该如下所示-
相关问题 更多 >
编程相关推荐