【发布时间】:2020-09-21 14:37:59
【问题描述】:
我想在对多个页面进行图像抓取后下载。但是,无法下载所有图像,因为它们被 [for syntax] 覆盖。
下面是我的代码。怎么了?
from urllib.request import urlopen
from bs4 import BeautifulSoup
import requests as rq
for page in range(2,4):
baseUrl = 'https://onepiecetreasurecruise.fr/Artwork/index.php?page=index'
plusUrl = baseUrl + str(page)
html = urlopen(plusUrl).read()
soup = BeautifulSoup(html, 'html.parser')
img = soup.find_all(class_='card-img-top')
listimg = []
for i in img:
listimg.append(i['src'])
n = 1
for index, img_link in enumerate(listimg):
img_data = rq.get(img_link).content
with open('./onepiece/' + str(index+1) + '.png', 'wb+') as f:
f.write(img_data)
n += 1
【问题讨论】:
标签: image for-loop beautifulsoup download web-crawler