0

I have the code that prints all image_url that i want to download
Next I want to save them in a local folder with folder_name=scrap_images
with desired image_name=uni_name that is also in the output
can you help me out.

response   = requests.get('https://www.eduvision.edu.pk/admissions.php? 
discipline_type=Social-Sciences&sub_level=7&city=&pageNo=2',headers=header)
soup       = BeautifulSoup(response.content, 'html.parser')
data=soup.findAll('div',attrs={'class':'col-lg-12 col-xs-12'})[:-1]
for d in data:
   uni_name,comma,city = (d.findAll('a')[1].text).partition(',')
   print(uni_name)
   admis_img = d.img['src']
   if(d.img['src']=="images_post/nust.jpg"):
       admis_img= "https://www.eduvision.edu.pk/"+d.img['src']
       print(admis_img)
   else:
       print(admis_img)

1 Answers1

0

The simplest way to download images using python is using the Requests Module.

You can read more about it here, it will help you get started with it, I have attached a code sample as well for you.

You can also refer to this answer for a better understanding of your query.

# importing the requests library 
import requests

`# api-endpoint 
URL = "http://maps.googleapis.com/maps/api/geocode/json"`

# location given here 
location = "ImageKit"

# defining a params dict for the parameters to be sent to the API 
PARAMS = {'address':location}

# sending get request and saving the response as response object 
r = requests.get(url = URL, params = PARAMS) 

# extracting data in json format 
data = r.json() 


# extracting latitude, longitude and formatted address  
# of the first matching location 
latitude = data['results'][0]['geometry']['location']['lat'] 
longitude = data['results'][0]['geometry']['location']['lng'] 
formatted_address = data['results'][0]['formatted_address'] 

# printing the output 
print("Latitude:%s\nLongitude:%s\nFormatted Address:%s"
      %(latitude, longitude,formatted_address)) 
AssaultKoder95
  • 188
  • 1
  • 9