Ask AI
Skip to main content

Select elements from HTML

Function: Select elements from HTML

This function helps you extract specific pieces of information from a block of HTML code, such as content from a web page. Imagine you have the entire content of a webpage, and you only want to grab all the headlines, or all the links, or specific product descriptions. This action allows you to "point" to those specific parts using simple instructions, and it will give you back a list of what it found.

Input,

  • HTML: This is the full HTML content (like the source code of a webpage) that you want to search through. It's the raw material from which you'll extract information.
  • Selectors: This is a list of instructions that tell the system exactly what to look for within the HTML. Each instruction is like a specific address or pattern (e.g., "all paragraphs," "all links," "the main title"). You can provide multiple selectors to find different types of content.

Output,

  • Result: A list of text snippets. Each item in this list will be the inner content (the text and any HTML inside) of the elements found by your selectors.

Execution Flow,

Real-Life Examples,

  1. Extracting Product Names from an E-commerce Page:

    • Inputs:
      • HTML: <html><body><h2 class="product-name">Laptop X</h2><p>Description...</p><h2 class="product-name">Mouse Y</h2></body></html>
      • Selectors: ["h2.product-name"]
    • Result: The application would return a list containing ["Laptop X", "Mouse Y"]. This list could then be used to populate a product catalog or send notifications.
  2. Gathering All Links from a Blog Post:

    • Inputs:
      • HTML: <html><body><p>Read more <a href="https://example.com/article1">here</a> and also check out <a href="https://example.com/article2">this</a>.</p></body></html>
      • Selectors: ["a"]
    • Result: The application would return a list containing ["here", "this"]. This list could be used to verify external links or create a summary of referenced articles.
  3. Pulling Specific Data from a Table:

    • Inputs:
      • HTML: <html><body><table><tr><td>Item 1</td><td class="price">$10.00</td></tr><tr><td>Item 2</td><td class="price">$25.50</td></tr></table></body></html>
      • Selectors: ["td.price"]
    • Result: The application would return a list containing ["$10.00", "$25.50"]. This list could be used to track prices, perform calculations, or update a price comparison tool.