<jupyter_start><jupyter_text>Scraping quotes images from inspirational quotes website<jupyter_code>import os
import bs4
import requests
str = input()
input_str = str
str = str.replace(" ", "&20")

str
url = "https://www.snapdeal.com/search?keyword={}&santizedKeyword=&catId=&categoryId=0&suggested=false&vertical=&noOfResults=20&searchState=&clickSrc=go_header&lastKeyword=&prodCatId=&changeBackToAll=false&foundInAll=false&categoryIdSearched=&cityPageUrl=&categoryUrl=&url=&utmContent=&dealDetail=&sort=rlvncy".format(str)
print(url)
response = requests.get(url)
response.content
# HTML Parser --> parsed html into python object
soup = bs4.BeautifulSoup(response.content)
print(type(soup))
picture_element = soup.findAll('picture')
print(type(picture_element))
print(len(picture_element))
picture = picture_element[0]
print(picture_element)
picture.img.attrs['src']
img_url = picture.img.attrs['src']

with open('snap.jpg', 'wb') as file:
    
    response = requests.get(img_url)
    
    file.write(response.content)
for i, picture in enumerate(picture_element):
    try: 
        os.mkdir(input_str)
        with open('{}/{}-{}.jpg'.format(input_str, input_str, i), 'wb') as file:
            try:
                img_url = picture.img.attrs['src']
                response = requests.get(img_url)
                file.write(response.content)
            except KeyError:
                img_url = picture.img.attrs['data-src']
                response = requests.get(img_url)
                file.write(response.content)
    except FileExistsError:
        for f in os.listdir(input_str):
            os.remove(os.path.join(input_str, f))
        os.rmdir(input_str)
        with open('{}-{}.jpg'.format(input_str, i), 'wb') as file:
            try:
                img_url = picture.img.attrs['src']
                response = requests.get(img_url)
                file.write(response.content)
            except KeyError:
                img_url = picture.img.attrs['data-src']
                response = requests.get(img_url)
                file.write(response.content)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13134186818397345, 'fraction_numerical': 0.003793266951161688, 'mean_word_length': 3.1535433070866143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '393654', 'license': 'MIT', 'n_tokens_mistral': 685, 'n_tokens_neox': 649, 'n_words': 109, 'path': '05-data_acquisition/image_scraping.ipynb', 'repo_name': 'sachinpr0001/data_science', 'size': '2109'}