liveBook · Manning

Scraping

As explained in AI Agents and Applications

Page scraping is the programmatic extraction of content from web pages.

Scraping is the programmatic extraction of text from web pages. In a research summarization engine, it turns result URLs into source material that an LLM can summarize, preserve with its URL, and combine into a report. section 4.1 section 4.7.3

A practical scraping stage passes each search result through a small processing chain:

  • Receive a dictionary containing the result URL, search query, and user question. section 4.7.3
  • Call a web_scrape function with the URL and retain at most 10,000 characters of returned text. section 4.7.3
  • Send the extracted text to a summary prompt while passing the source URL and question alongside the result. section 4.7.3
  • Map the chain across multiple URLs in parallel, then join the individual summaries into research input. section 4.7.3

Astorga research query

For a question about things to see in Astorga, search results provide URLs such as travel and attraction pages. Scraping one page produces text that can be summarized into findings about attractions, history, cuisine, and natural beauty, with the source URL included. section 4.6.4 section 4.7.3

Listing 4.10 Search Result Text and Summary chain
from llm_models import get_llm
from web_scraping import web_scrape
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnableLambda, RunnableParallel
from prompts import (
    SUMMARY_PROMPT_TEMPLATE
)

RESULT_TEXT_MAX_CHARACTERS = 10000

search_result_text_and_summary_chain = (
    RunnableLambda(lambda x:
        {
            'search_result_text': 
                web_scrape(url=x['result_url'])[
                    :RESULT_TEXT_MAX_CHARACTERS],
            'result_url': x['result_url'], 
            'search_query': x['search_query'],
            'user_question': x['user_question']
        }
    )
    | RunnableParallel (
        {
            'text_summary': SUMMARY_PROMPT_TEMPLATE 
               | get_llm() | StrOutputParser(),
            'result_url': lambda x: x['result_url'],
            'user_question': lambda x: x['user_question']            
        }
    )
    | RunnableLambda(lambda x: 
        {
            'summary': 
               f"Source Url: {x['result_url']}\nSummary:
               {x['text_summary']}",
            'user_question': x['user_question']
        }
    ) 
)

Inspect the chain implementation showing URL scraping, text truncation, metadata preservation, and parallel summarization. section 4.7.3

How AI Agents and Applications covers it

How deep it goes
Explains a runnable implementation with metadata flow, character limiting, parallel mapping, and summary joining, but not scraping internals.
Examples
Uses Astorga attraction searches, travel URLs, extracted page text, and a source-preserving summary as concrete artifacts.
What it assumes
Assumes web-search results, URLs, Python dictionaries, and basic LangChain runnable composition while building the scraping stage incrementally.
What you can do after
Build it from scratch as a Python and LangChain chain that extracts, limits, summarizes, and combines text from multiple URLs.
How it connects
Connects web scraping with web search, LLM summarization, LangChain runnable chains, source attribution, and research reports.

Also explained in

Compare how 9 books explain scraping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents and Applications. The section links point to the parts of the book it draws on.