Web scraping doubt

i am trying to scrape images from Snapdeal but there are no article tags, the img tag is under the div element and there are a lot of div elements that dont have the img tag aswell

i have tried different approaches that i could think of, please let me know what should i be doing for the same?

Hey @devchopra999_11c6416ab7f09bbf,
Inspect the website carefully, you will find that all the product images are in in class “product-img” then get this class first then extract the all images from this class.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

i did try that but it doesnt give any output, no file is being created and it doesnt even give an error

import bs4
import requests
url="https://www.snapdeal.com/search?clickSrc=top_searches&keyword=earbuds&categoryId=0&vertical=p&noOfResults=20&SRPID=topsearch&sort=rlvncy"
response = requests.get(url)
soup=bs4.BeautifulSoup(response.content)
section_element=soup.findAll("section")
for i,section in enumerate(section_element):
if section_element[i].attrs['class']=="['product-image', 'lazy-load']":
    url=section_element[i].img.attrs['data-src']
    with open("snapdeal{}.jpg".format(i),"wb") as file:
        rsp=requests.get(url)
        file.write(rsp.content)

Hey @devchopra999_11c6416ab7f09bbf,
You have to inspect it carefully and find first class containing images i.e. “product-img” class then you have to get all classes by the name of “product-img” by using “prods = soup.findAll(class_ = “product-img”)” then from this you have to take the image attribute “data-src” which is holding the url of images of product and then you can write it on file. The key is the better you inspect the easier would be to write code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.