News Feed Forums General Web Scraping How can I scrape product name, price, stock status from Extra Brazil Java Jsoup?

  • How can I scrape product name, price, stock status from Extra Brazil Java Jsoup?

    Posted by Rutendo Urvashi on 12/12/2024 at 10:01 am

    To scrape the product name from Extra Brazil, you can use Java with the Jsoup library. The product name is often located within an h1 or span tag with a specific class. Using Jsoup’s select() method, you can extract the name after fetching the page.

    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    public class ScrapeExtra {
        public static void main(String[] args) throws Exception {
            // Fetch the product page
            Document doc = Jsoup.connect("https://www.extra.com.br/product-page").get();
            // Extract the product name
            Element productName = doc.selectFirst("h1.product-title");
            System.out.println("Product Name: " + productName.text());
        }
    }
    
    Ariah Alfred replied 1 week, 2 days ago 3 Members · 2 Replies
  • 2 Replies
  • Paula Odalys

    Member
    12/13/2024 at 7:35 am

    To extract the price from Extra Brazil, locate the element containing the pricing information, typically within a div or span tag with a class indicating the price. Using Jsoup’s select() method, you can fetch and parse this element.

    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    public class ScrapeExtra {
        public static void main(String[] args) throws Exception {
            // Fetch the product page
            Document doc = Jsoup.connect("https://www.extra.com.br/product-page").get();
            // Extract the product price
            Element price = doc.selectFirst(".product-price");
            System.out.println("Price: " + price.text());
        }
    }
    
  • Ariah Alfred

    Member
    12/13/2024 at 8:32 am

    For scraping the stock status, you can target the section indicating whether the product is in stock or out of stock. Using Jsoup, fetch the relevant HTML tag and extract its text to display availability.

    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    public class ScrapeExtra {
        public static void main(String[] args) throws Exception {
            // Fetch the product page
            Document doc = Jsoup.connect("https://www.extra.com.br/product-page").get();
            // Extract stock status
            Element stockStatus = doc.selectFirst(".stock-status");
            System.out.println("Stock Status: " + stockStatus.text());
        }
    }
    

Log in to reply.