Lesson

From One Element to All Entries: find_all, Numbers and Missing Values

Read every entry of a real arXiv list with Beautiful Soup: find_all and a list comprehension, the number of authors of each paper, the maximum and the mean, text that becomes a number, and entries that do not have a value.

Last updated:


In this lesson we learn how Beautiful Soup collects all the elements that fit, how a list comprehension turns them into data, how text that holds a number is converted to a number, and what to do when an element is missing from some of the entries.

Which paper has the most authors?

Papers in hardware architecture are often the work of a team:
some have one author and some have ten. On the arXiv list of October 2026 we ask how many authors a paper has, which paper has the most, and how many there are on average.
The saved copy of the list holds the first 25 of its 266 entries, so the answers describe these 25 papers and not the whole month.

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 requests the saved copy of the list and builds the soup, as in From a Web Page to Data: Beautiful Soup, so that this page stands on its own.

import requests
from bs4 import BeautifulSoup

list_url = (
    'https://dvirross.com/materials/courses/'
    'intro-data-science/arxiv-cs-ar-2026-10.htm'
)
page_text = requests.get(list_url).text
soup = BeautifulSoup(page_text, 'html.parser')
print(soup.title.text)
Hardware Architecture Oct 2026

find_all: every element that fits

Each paper of the list is a dd element that holds its title, its authors and its subjects.
The method find_all returns all the elements that fit, as a list, in the order of the page.
It takes the same arguments as find.

entries = soup.find_all('dd')
print(len(entries))
25

The list entries has 25 elements, one for each paper, and each one has its own find, which looks only inside it.
The steps that read the title of one paper go into a function, title_of.
A list comprehension builds a list from another list in one line:
the expression before for is computed for every element, here the call of title_of.

def title_of(entry):
    box = entry.find('div', class_='list-title')
    return box.text.replace('Title:', '').strip()

titles = [title_of(entry) for entry in entries]
print(len(titles))
print(titles[0])
print(titles[1])
25
SyntheticHLS: Building Diverse Synthetic High-Level Synthesis Datasets using LLMs
ShatterQuant: Breaking Uniform Precision with Block-Wise Mixed-Precision on a Systolic Transformer Hardware Accelerator

Counting the authors

The authors of a paper are in a div of the class list-authors, and each author is a link, an element a.
So the number of authors is the number of links inside that div:
find_all returns a list and len counts it. Run the box and look at the result for the second paper, entries[1]:
the number of links in its list-authors.

authors = entries[1].find('div', class_='list-authors')
print(len(authors.find_all('a')))
5

The steps that read one paper are the same for all papers, so we put them in a function, which returns the pair of the title and the number of authors, and call it on every entry.
A pair like this is a tuple.

def read_entry(entry):
    authors = entry.find('div', class_='list-authors')
    return (title_of(entry), len(authors.find_all('a')))

papers = [read_entry(entry) for entry in entries]
print(papers[0])
('SyntheticHLS: Building Diverse Synthetic High-Level Synthesis Datasets using LLMs', 3)

The maximum and the mean

Self-study, importance 1 This part is for self-study: it is not taught in the lecture, and you read it on your own. The maximum of a list of pairs and the mean of a list of numbers. It helps with: maximum and average over a list of scraped values.

papers is a list of 25 pairs. The function max returns the largest item, and its argument key says what to compare:
here a function that takes a pair and returns its second part, the number of authors, written as lambda paper: paper[1].
The mean is the sum divided by the count, and round(number, 2) keeps two digits after the decimal point.

top = max(papers, key=lambda paper: paper[1])
print(top[1], top[0])

counts = [paper[1] for paper in papers]
print(round(sum(counts) / len(counts), 2))
10 PEEK: Heterogeneous Parallelism for Privileged Error Detection in Safety-Critical Processors
4.2

Among these 25 papers the largest team has 10 authors, and the mean is 4.2 authors per paper.
The mean is higher than a typical paper: half of the papers have 4 authors or fewer, and a few large teams raise the mean.

Text that holds a number

The page says how many entries the month has, in the line Total of 266 entries, in a div of the class paging.
The text is not a number, and a program cannot compute with it.
The method split() cuts a text at its spaces and returns a list of its words; [2], the third word, counted from 0, is '266', and the function int converts the text of a whole number to a number.

paging = soup.find('div', class_='paging')
total = int(paging.text.split()[2])
print(total)
print(len(entries), 'of', total)
266
25 of 266

Without int, the program would hold the text '266', and '266' + 1 would be an error.
A number written with a thousands separator, such as 3,330, needs one more step, which is replace(',', ''), because int does not read the comma.

A number with a decimal point is converted with float, and a unit written after it is removed first.
The page of a paper writes the size of its submission as 3,330 KB, and the same steps give the number:

size_text = '3,330 KB'
number = size_text.replace(' KB', '').replace(',', '')
print(float(number))
3330.0

An element that is missing

Not every paper has the line of comments, in which the authors write, for example, the number of pages.
In the list, 13 of the 25 papers have no div of the class list-comments at all.
For such an entry find returns None, and None.text is an error.
A program that reads many entries tests for None before it reads.

without_comments = [
    entry for entry in entries
    if entry.find('div', class_='list-comments') is None
]
print(len(without_comments))
13

When the comments exist, they are free text written by the authors, such as 7 pages, 5 figures. Accepted to ASP-DAC 2027.
A program reads a number of pages only where the text says it, in the form that a number comes first and the word pages after it.
The method isdigit() tells whether a text is made of digits only, and startswith('pages') whether a text begins with the word.
The function returns None for every entry that does not say.

def pages_of(entry):
    box = entry.find('div', class_='list-comments')
    if box is None:
        return None
    words = box.text.replace('Comments:', '').split()
    if len(words) < 2:
        return None
    if words[0].isdigit() and words[1].startswith('pages'):
        return int(words[0])
    return None
all_pages = [pages_of(entry) for entry in entries]
print(all_pages)
[None, None, 7, None, 4, 4, None, None, None, None, 8, None, None, None, 10, 15, None, None, None, None, None, None, None, None, None]

A missing number is not zero. To compute with the numbers that exist, we keep only the items that are not None, and the mean is over those:

known = [pages for pages in all_pages if pages is not None]
print(len(known), max(known), sum(known) / len(known))
6 15 8.0

Only 6 of the 25 papers say how many pages they have, and these 6 have 8 pages on average and at most 15.
The number describes the papers that say, which may be different from the papers that do not.

Practice

Your turn. The list papers holds a pair of the title and the number of authors for each paper.
Print the title of the paper that has the fewest authors; when several papers have the fewest, print the first of them in the list.
The function min takes the same argument key as max; both appeared in Python for Databases 2: Loops and Functions.

# your code here
Show a hint

The function min works like max, with the same argument key.
It returns the first of the items that have the smallest value.

Show a solution
fewest = min(papers, key=lambda paper: paper[1])
print(fewest[0])
A Compression Tree Generation Method for High Performance VLSI Datapaths
Show a common mistake and why it happens
fewest = max(papers, key=lambda paper: paper[1])
print(fewest[0])

The function max returns the paper with the most authors, not the fewest.

Self-study, importance 2 This part is for self-study: it is not taught in the lecture, and you read it on your own. Two more practice tasks: counting and a mean. It helps with: counting items by a condition, and a mean that skips a missing value.

Your turn. Print how many of the 25 papers have at least 5 authors, as one number.

# your code here
Show a hint

Build a list of the pairs whose second part is at least 5 with a condition at the end of a list comprehension, and print its length.

Show a solution
large = [paper for paper in papers if paper[1] >= 5]
print(len(large))
9
Show a common mistake and why it happens
large = [paper for paper in papers if paper[1] > 5]
print(len(large))

The condition > 5 leaves out the papers with exactly 5 authors, and “at least 5” includes them.

Your turn. The function pages_of above returns the number of pages of an entry, or None.
Print the mean number of pages, rounded to one digit after the decimal point, over the papers that say how many pages they have.

# your code here
Show a hint

Keep only the values that are not None, as in the list known, and divide their sum by their count, not by the number of entries.

Show a solution
numbers = [pages_of(entry) for entry in entries]
numbers = [n for n in numbers if n is not None]
print(round(sum(numbers) / len(numbers), 1))
8.0
Show a common mistake and why it happens
numbers = [pages_of(entry) for entry in entries]
numbers = [n for n in numbers if n is not None]
print(round(sum(numbers) / len(entries), 1))

The sum is over the 6 papers that say, but the division is by all 25 entries, which treats a missing number as if it were zero pages.
The result, 1.9, describes no paper.

Keep in mind

  • find_all returns a list of all the elements that fit; an element of the list has its own find and find_all.
  • A list comprehension turns the list of elements into a list of data; a function that reads one entry keeps the code in one place.
  • The text of an element is text: int(...) converts text of a whole number, float(...) a number with a decimal point, split() cuts a text into words, and a unit or a thousands separator is removed with replace first.
  • An element that is missing gives None from find; test is None before reading text, and keep a missing value out of a mean, because it is not zero.
  • max and min with key return the item with the largest or the smallest value of a part of it.