A request versus a browser

Most of the LangChain course, and most simple web scraping, works by sending an HTTP request and reading back whatever text the server sends. That's fast, cheap, and works fine for a lot of the web. It breaks down the moment a page needs JavaScript to finish building itself, needs a click to reveal something, or needs a login before it will show anything useful at all.

Playwright solves that by not sending a request at all. Instead, it starts an actual browser, the same kind of program you already use every day, and drives it programmatically: open this URL, click that button, type into that field, read back what's on screen now. The browser does all the same work it would do for a human: downloading the page, running its JavaScript, laying it out, and rendering it. Playwright just sits in the driver's seat instead of you.

Why an agent needs this

An AI agent that only knows how to send HTTP requests can read static pages, but it can't do anything the web was actually built for: logging in, submitting a search, clicking through a multi-step flow, or waiting for content that only appears after some JavaScript runs. Giving an agent a browser, through a library like Playwright, gives it hands: the same basic actions a person has, click, type, read, scroll, wait.

This course builds that up gradually. The beginner tier here is just plain Python controlling a browser, no AI involved at all, exactly like Lesson 13 in the LangChain course built a calculator tool before any model ever touched it. The AI only gets wired in starting at Lesson 16, once there's something real for it to control. See this course's README for the full lesson list and prerequisites.

Playwright versus Selenium

If you've heard of browser automation before, it was probably through Selenium, an older tool that does a similar job. Playwright, built by Microsoft, is newer and was designed with the lessons of Selenium's rough edges already learned: it waits for elements automatically instead of making you write manual sleep() calls (more on this in Lesson 9), it talks to Chromium, Firefox, and WebKit through one consistent API, and its Python library ships with everything needed to install real browser binaries with a single command (Lesson 2).

The code, piece by piece

This lesson has no live browser code, that starts in Lesson 3. What's here is a plain Python dictionary laying out the reasons a script might need a browser instead of a simple request, printed out so you can read them slowly instead of all at once in prose.

WHY_A_BROWSER = {
"Reading rendered pages": (...),
"Clicking and typing": (...),
...
}

Each key is a short reason, each value is one or two sentences explaining it. main() just loops over the dictionary and prints both.

for reason, explanation in WHY_A_BROWSER.items():
print(f"
{reason}:")
print(f" {explanation}")

.items() on a dictionary gives you both the key and the value together, one pair at a time, which is the usual way to loop over a dictionary in Python when you need both.

Checkpoint

  • Browser automation: controlling a real browser (Chromium, Firefox, or WebKit) with code instead of a mouse and keyboard.
  • Playwright: the library this course uses to do that, built by Microsoft, and this course's sync API only, not the async one.
  • Why a browser, not just requests: JavaScript-rendered content, clicking and typing, logging in, and looking like a real visitor rather than a bot.
  • This tier is AI-free: the beginner tier is plain Python controlling a browser. The AI only shows up starting at Lesson 16.

If anything here still feels unclear, ask before moving to Lesson 2.