View Single Post
Old 02-25-2025, 10:02 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,212
using the prompt:

'write me a piece of code that fetches the html content from gfy.com and grabs all the image links and just print out the urls to those images"

results:

Fetching Image Links from Gfy.com

Requirement Summary

The task is to create a Python script that fetches the HTML content from the website gfy.com, extracts all image links, and prints out the URLs of those images.

This can be accomplished using various libraries in Python, such as requests for fetching the content and BeautifulSoup for parsing the HTML.

Using Requests and BeautifulSoup

Code:
import requests
from bs4 import BeautifulSoup

def fetch_image_links(url):
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    
    image_links = []
    for img in soup.find_all('img'):
        img_url = img.get('src')
        if img_url:
            image_links.append(img_url)
    
    return image_links

if __name__ == "__main__":
    url = 'https://gfy.com'
    images = fetch_image_links(url)
    for link in images:
        print(link)
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote