I'm using concurrent futures to scrape a list of H1s from Webpages and append them to a list called archive_h1_list. The issue is, as soon as concurrent futures hits an exception, it stops appending the list.
When I print the resultant list below, it stops after the first exception. ['Example Domain', 'Example Domain', 'Exception Error!'] it never continues to process the last https://www.example.com h1 in the list after hitting an exception.
import concurrent.futures
from urllib.request import urlopen
from bs4 import BeautifulSoup
CONNECTIONS = 8
archive_url_list = ["https://www.example.com", "https://www.example.com", "sdfihaslkhasd", "https://www.example.com"]
archive_h1_list = []
def get_archive_h1(h1_url):
html = urlopen(h1_url)
bsh = BeautifulSoup(html.read(), 'lxml')
return bsh.h1.text.strip()
def concurrent_calls():
with concurrent.futures.ThreadPoolExecutor(max_workers=CONNECTIONS) as executor:
f1 = executor.map(get_archive_h1, archive_url_list)
try:
for future in f1:
archive_h1_list.append(future)
except Exception:
archive_h1_list.append("Exception Error!")
pass
The expected output should be:
['Example Domain', 'Example Domain', 'Exception Error!', 'Example Domain']