def searchImage(): if request.method == "POST": search_term = request.form[ 'keyword'] # assigning the value of the input keyword to the variable keyword else: print("Please enter something") imagescrapperutil = BusinessLayer ## Instantiate a object for ScrapperImage Class imagescrapper = ScrapperImage() list_images = os.listdir('static') imagescrapper.delete_downloaded_images( list_images) ## Delete the old images before search image_name = search_term.split() image_name = "+".join(image_name) ## We need to add the header metadata header = { 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" } lst_images = imagescrapperutil.downloadImages(search_term, header) return displayImages() # redirect the control to the show images method
def searchImage(): if request.method == "POST": #it becomes true as soon as we click submit button search_term = request.form[ 'keyword'] # assigning the value of the input keyword to the variable keyword #'keyword' contains what to be searched like dog,cat etc #next, we send the search_term to business layer else: print("Please enter something") imagescrapperutil = BusinessLayer ## Instantiate a object for ScrapperImage Class imagescrapper = ScrapperImage() list_images = os.listdir('static') imagescrapper.delete_downloaded_images( list_images) ## Delete the old images before search # image_name=search_term.split() #image_name="+".join(image_name) ## We need to add the header metadata header = { 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36" } lst_images = imagescrapperutil.downloadImages(search_term, header) return displayImages() # redirect the control to the show images method
def searchImage(): if request.method == 'POST': #assigning te value of the input keyword to the variable search_term = request.form['keyword'] else: print("Please enter something") imageScrapperUtil = BusinessLayer## Instantiate a object for ScrapperImage Class imageScrapper = ScrapperImage() list_images = os.listdir('static') imageScrapper.delete_downloaded_images(list_images) ##Delete the old image before search header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"} lst_images = imageScrapperUtil.downloadImages(search_term, header) return displayImages()
def searchImages(): if request.method == 'POST': search_term = request.form['keyword'] else: print('Please enter something') imagescrapperutil = BusinessLayer imagescrapper = ScrapperImage() list_images = os.listdir('static') imagescrapper.delete_images(list_images) image_name = search_term.split() image_name = "+".join(image_name) header = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 Safari/537.36 ' } lst_images = imagescrapperutil.downloadImages(search_term, header) return displayImages()