Это хорошая проблема. Формат данных здесь немного отличается, и здесь необходимо провести оптимизацию.
Ссылка на веб-сайт - https://www.ready.gov/active-shooter
import requests
from bs4 import BeautifulSoup
res = requests.get("https://www.ready.gov/active-shooter")
soup = BeautifulSoup(res.text, "lxml")
div = soup.find("div",class_="field-item even")
data = []
for ele in div.findChildren():
if ele.name == "h2":
if temp:
data.append(temp)
temp = {}
temp["heading"] = ele.text.strip()
else:
if ele.name=="ul":
description = [i.text.strip() for i in ele.find_all("li")]
if "description" not in temp: temp["description"] = []
temp["description"].append(description)
elif ele.name == "h3":
if "sub-heading" not in temp: temp["sub-heading"] = []
temp["sub-heading"].append(ele.text.strip())
print(data)
Вывод:
[{'heading': 'Associated Content',
'description': ['RUN. HIDE. FIGHT.® Surviving an Active Shooter Event - English (Video)',
'Active Shooter Information Sheet (PDF)',
'Department of Homeland Security (DHS) Active Shooter Preparedness Resources (Training, videos, brochures and more for individualized audiences link)',
'Department of Homeland Security (DHS) Active Shooter Preparedness Resources Translated (Link)',
'Conducting Security Assessments: A Guide for Schools and Houses of Worship Webinar (Link)']},
{'heading': 'Be Informed',
'description': ['Sign up for an active shooter training.',
'If you see something, say something to the authorities right away.',
'Sign up to receive local emergency alerts and register your contact information with any work-sponsored alert system.',
'Be aware of your environment and any possible dangers.']},
{'heading': 'Make a Plan',
'description': ['Make a plan with your family and make sure everyone knows what to\xa0do if confronted with an active shooter.',
'Wherever you go look for the two nearest exits, have an escape path in mind and identify places you could hide if necessary.',
'Understand the plans for individuals with disabilities or other access and functional needs.']},
{'heading': 'During',
'sub-heading': 'FIGHT\xa0as an absolute last resort.',
'description': ['Commit to your actions and act as aggressively as possible against the shooter.',
'Recruit others to ambush the shooter with makeshift weapons like chairs, fire extinguishers, scissors, books, etc.',
'Be prepared to cause severe or\xa0lethal injury to the shooter.',
'Throw items and improvise weapons to distract and disarm the shooter.']},
{'heading': 'After',
'description': ['Keep hands visible and empty.',
'Know that law enforcement’s first task is to end the incident and they may have to pass injured along the way.',
'Officers may be armed with rifles, shotguns or handguns and may use pepper spray or tear gas to control the situation.',
'Officers will shout commands and may push individuals to the ground for their safety.',
'Follow law enforcement instructions and evacuate in the direction they come from unless otherwise instructed.',
'Take care of yourself first, and then you may be able to help the wounded before first responders arrive.',
'If the injured are in immediate danger, help get them to safety.',
'While you wait for first responders to arrive, provide first aid. Apply direct pressure to wounded areas and use tourniquets if you have been trained to do so.',
'Turn wounded people onto their sides if they are unconscious and keep them warm.',
'Consider seeking professional help for you and your family to cope with the long-term effects of the trauma.']}]