I have this code where I want to crawl images from a given website
from bs4 import *
import requests as rq
import os
import sys
page_url = sys.argv[1]
crawl = str(page_url)
r2 = rq.get('https://www.' crawl '' '/')
soup2 = BeautifulSoup(r2.text, "html.parser")
images = []
image_sources = soup2.select('img')
for img in image_sources:
images.append(img['src'])
for l in images:
print(l)
how can a crawl for example only 15 images?
CodePudding user response:
To get max 15 images you can do:
...
for img in image_sources[:15]: # <--- max. 15 images
images.append(img['src'])
...