[英]Python Scrape Images From a Slideshow
要获取滑块中的 9 个图像,您可以使用以下示例:
import requests
from bs4 import BeautifulSoup
url = 'http://www.buddingmindsinternationalschool.com/'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
for img in soup.select('#rev_slider_2_1 img'):
print(img['src'])
印刷:
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/banner-4.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/banner-2.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/banner-7.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/10/bannerfour.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/bannerseven.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/bannerfives-1.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/banner-5.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/bannereight.jpg
http://www.buddingmindsinternationalschool.com/wp-content/uploads/2017/11/banner-6.jpg
尝试这个:
import requests
from bs4 import BeautifulSoup
url = "http://www.buddingmindsinternationalschool.com/"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
for tag in soup.select(".rev-slidebg"):
img_name = tag['src'].split('/')[-1]
with open(img_name, "wb") as f:
req = requests.get(tag['src'])
f.write(req.content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.