You can download this code by clicking the button below.
This code is now available for download.
Extracts image links from the given HTML content using a specified tag (default is 'img').
Technology Stack : PyQuery
Code Type : Function
Code Difficulty : Intermediate
def extract_images_from_html(html_content, tag='img'):
from pyquery import PyQuery as pq
def extract_images(query_set):
images = []
for element in query_set.items():
src = element.attr('src')
if src:
images.append(src)
return images
pq_html = pq(html_content)
images = extract_images(pq_html(tag))
return images