LessonSelf-study

From a List to Many Pages: Following Links

Follow the links of a real arXiv list to the page of each paper, read attributes of meta tags, turn text such as 3,330 KB into numbers, handle a missing element, and compute the maximum and the mean over the scraped values.

Self-study This page is for self-study: it is not taught in the lecture, and you read it on your own.

Last updated:


In this lesson we learn how a program follows the links of a list to the page of each item, reads data from the tags that describe a page, turns text such as 3,330 KB into a number, and collects the results of many pages in one list.

How large is the submission of each paper?

The list of papers shows the title, the authors and the subjects of each paper, but not the size of the files that the authors submitted.
That number is on the page of each paper, which the list links to.
The question is: among the first eight papers of the list, which one has the largest submission, and what is the median size?
To answer it, a program has to read the list, follow eight links and read one number on each page.

The examples run in your browser: select Run from top to bottom, because the boxes of this page share their variables with each other.
If you press Stop or reload, run the page again from the top.
The first run of the page loads the libraries, so it can take a moment.

The notebooks of the lessons on reading web pages are one set, with the tasks numbered through it:

The first box defines soup_of, a function that requests an address and returns the soup of its page, as in From a Web Page to Data: Beautiful Soup, so that this page stands on its own.
It builds the soup of the list and collects the links to the papers:
every link whose attribute title is Abstract, as in From a Web Page to Data: Beautiful Soup.
A slice, [:8], keeps the first eight.

import requests
from bs4 import BeautifulSoup

copies = (
    'https://dvirross.com/materials/courses/'
    'intro-data-science/'
)

def soup_of(address):
    text = requests.get(address).text
    return BeautifulSoup(text, 'html.parser')

soup = soup_of(copies + 'arxiv-cs-ar-2026-10.htm')
anchors = soup.find_all('a', title='Abstract')
links = [a.get('href') for a in anchors][:8]
print(links[0])
print(len(links))
/abs/2610.00106
8

The href of a paper is /abs/2610.00106: the identifier of the paper is its last part, and the address is relative to the site of the list, https://arxiv.org.
On the live site the full address is the site name followed by the href.
The saved copies of the papers are kept under names of the form arxiv-abs-2610.00106.htm, so a function turns an href into the address of its copy.

def copy_address(href):
    paper_id = href.replace('/abs/', '')
    return copies + 'arxiv-abs-' + paper_id + '.htm'

page = soup_of(copy_address(links[0]))
print(page.find('h1', class_='title').text)
Title:SyntheticHLS: Building Diverse Synthetic High-Level Synthesis Datasets using LLMs

Data in the tags that describe the page

The head of every page holds meta elements: tags that are not drawn, which describe the page to search engines and to programs.
Each has an attribute name that says what it holds, and an attribute content that holds the value, for example the date in which the paper was submitted.
The first parameter of find is also called name, so writing name='citation_date' raises a TypeError; the attribute goes in the dictionary attrs, with the name that we want; get('content') reads its value.

date = page.find('meta', attrs={'name': 'citation_date'})
print(date.get('content'))
2026/09/09

The same page has one meta element for each author, with the name citation_author, so find_all with the same attrs counts the authors:

meta_name = {'name': 'citation_author'}
print(len(page.find_all('meta', attrs=meta_name)))
3

A number inside text

The size of the submission is written in the section of the page called the submission history, in a div of the class submission-history, as part of a line of text:
[v1] Wed, 9 Sep 2026 02:40:29 UTC (3,330 KB). The number is between a bracket and the letters KB, and it has a comma.
We take it in three steps. split('(') cuts the text at every opening bracket and returns a list of the pieces, and [-1], the last piece, is '3,330 KB)' with a line break.
These papers have one version each; with several versions the last piece is the size of the last one.
replace removes the letters and the comma, strip removes the line break, and int converts the text to a number.
The function repr shows a text as it is written, with its hidden characters, such as the line break \n.

box = page.find('div', class_='submission-history')
history = box.text
piece = history.split('(')[-1]
print(repr(piece))
number = piece.replace('KB)', '').replace(',', '')
kb = int(number.strip())
print(kb)
'3,330 KB)\n'
3330

Without the removal of the comma, int('3,330') raises an error.

A missing element stops the program

Some papers have a line of comments in the table of the page, an element td of the class comments, and some do not.
The comment of the first paper is there; the page of the second paper has none.
Asking for the text of an element that is not there is an error:

second = soup_of(copy_address(links[1]))
print(second.find('td', class_='comments').text)
AttributeError: 'NoneType' object has no attribute 'text'

find returned None, and None has no attribute text. A function that reads a page tests the element before it reads from it, and returns None for the value that does not exist.
The function below reads one paper and returns its data as a dictionary:
the identifier, the title from the meta tag, the size in KB, and the comment or None.

def read_paper(href):
    page = soup_of(copy_address(href))
    meta = {'name': 'citation_title'}
    title = page.find('meta', attrs=meta).get('content')
    box = page.find('div', class_='submission-history')
    piece = box.text.split('(')[-1]
    number = piece.replace('KB)', '').replace(',', '')
    kb = int(number.strip())
    comment = page.find('td', class_='comments')
    if comment is not None:
        comment = comment.text.strip()
    return {
        'id': href.replace('/abs/', ''),
        'title': title, 'kb': kb, 'comment': comment,
    }

second_paper = read_paper(links[1])
print(second_paper['kb'], second_paper['comment'])
19279 None

All eight pages

A for loop, or a list comprehension, calls the function on each link.
A program that sends many requests to one site waits between them, with time.sleep(seconds), as Reading pages responsibly explains; the copies on this site are not arXiv, so the box needs no pause.

papers = [read_paper(href) for href in links]
for paper in papers:
    print(paper['id'], paper['kb'])
2610.00106 3330
2610.00207 19279
2610.00311 856
2610.01186 866
2610.01603 492
2610.01623 234
2610.01867 747
2610.01918 159

The question of the lesson is answered by the maximum, the mean and the median of the sizes.
The median is the middle of the sizes in order: sorted puts them in order, and with eight values it is the mean of the two middle ones, at places 3 and 4 (counted from 0).

sizes = [paper['kb'] for paper in papers]
largest = max(papers, key=lambda paper: paper['kb'])
print(largest['kb'], largest['title'][:40])
print(round(sum(sizes) / len(sizes)))
ordered = sorted(sizes)
print((ordered[3] + ordered[4]) / 2)
19279 ShatterQuant: Breaking Uniform Precision
3245
801.5

The largest submission is 19,279 KB, the mean is 3,245 KB and the median is 801.5 KB.
One large paper pulls the mean up (the other seven have a mean of 955 KB) but not the median, so the median describes a typical paper.

Practice

Your turn. The function read_paper and the list papers are above.
Print how many of the eight papers have no comment on their page.

# your code here
Show a hint

In papers, a paper without a comment has None in its key 'comment'.
Count with a list comprehension and a condition is None.

Show a solution
without = [p for p in papers if p['comment'] is None]
print(len(without))
3
Show a common mistake and why it happens
without = [p for p in papers if p['comment'] == '']
print(len(without))

A missing comment is None, and None is not the empty text '', so the condition is never true and the program prints 0.

Your turn. The saved copy of the page of the paper 2610.00311 is at copies + 'arxiv-abs-2610.00311.htm'.
Print the date of its submission, from the meta tag citation_date.

# your code here
Show a hint

Build the soup of the page, find the meta element with attrs={'name': 'citation_date'} (not name='citation_date', which raises a TypeError) and read its attribute content with get.

Show a solution
other = soup_of(copies + 'arxiv-abs-2610.00311.htm')
date = other.find('meta', attrs={'name': 'citation_date'})
print(date.get('content'))
2026/09/28

The attribute name is written in attrs: writing name='citation_date' would raise a TypeError, because name is the first parameter of find.

Show a common mistake and why it happens
other = soup_of(copies + 'arxiv-abs-2610.00311.htm')
date = other.find('meta', attrs={'name': 'citation_date'})
print(date)

The program prints the whole meta tag. The date is the value of its attribute content, which get('content') reads.

Your turn. Print the mean size in KB of the seven papers other than the largest one, rounded to a whole number.

# your code here
Show a hint

Take the sizes in sizes, remove the largest with max(sizes) by a condition in a list comprehension, and divide the sum of the others by their count.

Show a solution
others = [kb for kb in sizes if kb != max(sizes)]
print(round(sum(others) / len(others)))
955
Show a common mistake and why it happens
others = [kb for kb in sizes if kb != max(sizes)]
print(round(sum(others) / len(sizes)))

The sum is over seven papers, and the division is by eight, the length of the full list, so the mean is too small.

Keep in mind

  • A list page links to the page of each item; the href of a link is the way, and a function that turns an href into an address keeps the code in one place.
  • find('meta', attrs={'name': ...}) and get('content') read the data that a page keeps in its meta tags.
  • A number inside text is cut out with split, cleaned with replace and strip, and converted with int.
  • An element that is missing is None; asking it for text raises an error, so a function tests for None and returns None.
  • The mean of a few values is pulled by a very large value; look at the maximum and the median next to the mean.
  • A program that reads a site keeps to its robots.txt, waits between requests, says who it is and takes only the data it needs.