← Lecture calendar

Scraping Data with a Coding Agent

For the course project, one option is to scrape a unique data set. Reddit is a particularly nice source because it has multiple sub-forums about basically any topic, so you can come up with a question and there will be data for it. This topic walks through the workflow.

Tools

Workflow

In VS Code, do File → Open Folder and select an empty folder for the project. By default the coding agent is only allowed to mess around with the folder that’s open; it cannot go elsewhere on your computer. That is the right safety level — it is OK to tell the agent it can run inside that folder, and it cannot do damage outside.

Then ask the agent to fetch data. A typical first prompt would be something like:

Download the most recent posts from r/datascience using Arctic Shift. Save the result to a JSON file.

It will figure out the URL, fetch the data, save the file. Open the file in the editor (press Alt+Z to wrap long lines so you can see what is in there).

Doing an analysis

Once you have data, ask for an analysis. For example:

Write a Python script that finds the 10 most frequent words used in the posts you downloaded.

The agent will create a script, run it, and report. You should audit:

If you want to compare:

Re-run the analysis without removing stop words.

That can give you the actual top 10 (which will be “the”, “a”, “to”, etc.). At the end of the day you have to know what is going on — when you write the report, you should know whether stop words were removed.

A worked example: drowning in r/boating

Suppose we want to study people’s worries about drowning. Boating is a subreddit. Workflow:

1. Use Arctic Shift to download ~1000 posts from r/boating.
2. Come up with a list of drowning-related keywords (let the agent suggest some).
3. Count how many posts have at least one of those keywords.

When we actually did this in class, it came out to roughly 7 in 10,000 — pretty rare. Obviously a silly analysis (we made it up on the spot), but it illustrates the shape of an end-to-end project: scrape a unique data set; ask a question that turns into a count or a ratio or a model; report.

Other data sources

A note on running the agent

These coding agents are usually OK at this kind of scraping task, but: