├── README.md └── imagedownloader.py /README.md: -------------------------------------------------------------------------------- 1 | # image-downloader 2 | 3 | Supporting code for YouTube tutorial video. 4 | -------------------------------------------------------------------------------- /imagedownloader.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | import os 4 | 5 | #url = 'https://www.airbnb.co.uk/s/Ljubljana--Slovenia/homes?tab_id=home_tab&refinement_paths%5B%5D=%2Fhomes&query=Ljubljana%2C%20Slovenia&place_id=ChIJ0YaYlvUxZUcRIOw_ghz4AAQ&checkin=2020-11-01&checkout=2020-11-08&source=structured_search_input_header&search_type=autocomplete_click' 6 | 7 | def imagedown(url, folder): 8 | try: 9 | os.mkdir(os.path.join(os.getcwd(), folder)) 10 | except: 11 | pass 12 | os.chdir(os.path.join(os.getcwd(), folder)) 13 | r = requests.get(url) 14 | soup = BeautifulSoup(r.text, 'html.parser') 15 | images = soup.find_all('img') 16 | for image in images: 17 | name = image['alt'] 18 | link = image['src'] 19 | with open(name.replace(' ', '-').replace('/', '') + '.jpg', 'wb') as f: 20 | im = requests.get(link) 21 | f.write(im.content) 22 | print('Writing: ', name) 23 | 24 | imagedown('https://www.airbnb.co.uk/s/Bratislava--Slovakia/homes?tab_id=home_tab&refinement_paths%5B%5D=%2Fhomes&place_id=ChIJl2HKCjaJbEcRaEOI_YKbH2M&query=Bratislava%2C%20Slovakia&checkin=2020-11-01&checkout=2020-11-22&source=search_blocks_selector_p1_flow&search_type=search_query', 'bratislava') 25 | --------------------------------------------------------------------------------