# Scrape images from DuckDuckGo # # With duckduckgo_images_api! from duckduckgo_images_api import search # import the library for scrape import time # to create delays :: for having a few seconds to check the console with open('speech.txt','r') as speech: # let's import the text qq = speech.readlines() # and split it in lines, it will create an array, a list print(qq) # print the array! time.sleep(2) # check qq in the console! # declare the first part of the text of the html, we will fill it # in the process with loops html = ''' 📡 💻📘 ''' # Elaborate each line :: process every element of the array qq # q is for "query", qq for "queries", because we will send requests to # DuckDuckGo searching the text of each line of speech.txt for q in qq: print(q) # print the q! time.sleep(2) # check current q in the console! q = q.strip() if q == '''''': # This nope. continue q = q.replace("\n","") # remove "\n", which means "return to the next line" # Scrape images with search()! # q is, indeed, the query for DuckDuckGo results = search(q) r = results["results"][0]["image"] # get the http link to the image html += f""" {q} \n""" # Now let's fill the html with text and the pic html += f""" \n""" # Close the html text html += ''' ''' html = html.replace(" '", "'") with open(',,/2_layout/3.html','w') as index: # Save the file! index.write(html)