Extracting Image Sources from HTML

  • Share this:

Code introduction


This function takes an HTML string as input, then uses the PyQuery library to parse the HTML, find all `<img>` tags, and return a list of `src` attributes from these tags.


Technology Stack : Python, PyQuery

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
def find_images_in_html(html):
    from pyquery import PyQuery as pq
    pq_html = pq(html)
    images = pq_html('img').items()
    return [img.attr('src') for img in images]                
              
Tags: