News Feed Forums General Web Scraping How to scrape flower prices from 1-800-Flowers.com using Python?

  • How to scrape flower prices from 1-800-Flowers.com using Python?

    Posted by Kajal Aamaal on 12/20/2024 at 12:40 pm

    Scraping flower prices from 1-800-Flowers.com using Python helps collect data about flower arrangements, pricing, and availability for analysis or price comparison. Using Python’s requests library for HTTP requests and BeautifulSoup for parsing HTML, you can retrieve structured data from their product pages. Below is a sample script for extracting flower details.

    import requests
    from bs4 import BeautifulSoup
    # Target URL for 1-800-Flowers
    url = "https://www.1800flowers.com/flowers"
    headers = {
        "User-Agent": "Mozilla/5.0"
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        soup = BeautifulSoup(response.content, "html.parser")
        flowers = soup.find_all("div", class_="product-card")
        for flower in flowers:
            name = flower.find("span", class_="product-name").text.strip() if flower.find("span", class_="product-name") else "Name not available"
            price = flower.find("span", class_="product-price").text.strip() if flower.find("span", class_="product-price") else "Price not available"
            print(f"Name: {name}, Price: {price}")
    else:
        print("Failed to fetch 1-800-Flowers page.")
    

    This script fetches the product page of 1-800-Flowers, parses the HTML content, and extracts flower names and prices. Pagination handling ensures that you scrape additional listings from other pages. Random delays between requests can be added to reduce the risk of detection by the website’s anti-scraping measures.

    Kajal Aamaal replied 2 days, 12 hours ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

Log in to reply.