使用BeautifulSoup从上一页抓取

时间:2019-07-25 20:41:09

标签: python web-scraping beautifulsoup

我正在抓取《美国公共卫生杂志》上发表的文章的元数据。我有兴趣了解每篇文章属于期刊的哪个部分。 table of contents for each issue列出了每个部分的标题和副标题(例如,在我刚刚链接的问题中,“ AJPH历史记录”是标题,而“知识分子”则是副标题)。问题在于该信息未包含在每篇文章的页面上。最多只有一个标签可以在更广泛的类别(即社论,书评,研究摘要,信函等)中声明文章的类型,而该类别与目录中的任何标题/小标题都不匹配。这是一个article page的示例。

如何修改我的代码,以便从文章页面中解析出我对每篇文章感兴趣的所有其他元数据,它会从目录页面中提取标题和子标题?我已经在下面粘贴了我的代码。

import requests
from bs4 import BeautifulSoup
import csv
import pandas as pd 
import re

json_data =[]
base_url = 'https://ajph.aphapublications.org'

#Get AJPH 2018 issues

ajph2018 = ['https://ajph.aphapublications.org/toc/ajph/108/12',
            'https://ajph.aphapublications.org/toc/ajph/108/S2',
            'https://ajph.aphapublications.org/toc/ajph/108/S3',
            'https://ajph.aphapublications.org/toc/ajph/108/S4',
            'https://ajph.aphapublications.org/toc/ajph/108/S5']

for a in ajph2018:
    issue=requests.get(a)
    soup1=BeautifulSoup(issue.text, 'lxml')

#Get articles
    doi = [a.get("href") for a in soup1.find_all("a", {"class":"ref nowrap"})]

    for each in doi:  
        articlelink = base_url + each
        article = requests.get(articlelink)
        soup2=BeautifulSoup(article.text, 'lxml')

        ajph18_dict={"articletype":"NaN", "title":"NaN", "volumeissue":"NaN", "date":"NaN", "author":"NaN", "url":"NaN"}
        authors=[]

        #Metadata for each article.   
        articletype=soup2.find("meta", {"name":"dc.Type"})
        title = soup2.find("h1",{"class":"chaptertitle"})
        volumeissue = soup2.find("title")
        date = soup2.find("a", {"href":re.compile("^/toc/ajph/108/")})
        authortag = soup2.find_all("contrib", {"contrib-type":"author"})
        url = articlelink

        if articletype is not None:
            ajph18_dict["articletype"]=articletype["content"].strip()

        if title is not None:
            ajph18_dict["title"]=title.text.strip()

        if volumeissue is not None:
            ajph18_dict["volumeissue"]=volumeissue.text.strip()

        if date is not None:
            ajph18_dict["date"]=date.text.strip()

        if authortag is not None:
            for coauthor in authortag:
                coauthor=coauthor.text.strip()
                authors.append(coauthor)
                ajph18_dict['author'] = authors

        if url is not None:
            ajph18_dict["url"]=url 

        json_data.append(ajph18_dict)

df=pd.DataFrame(json_data)
df.to_csv("ajph last.csv")

print("Saved")

1 个答案:

答案 0 :(得分:1)

您可以使用itertools.groupby对结果进行分组,以将每篇文章与其适当的标题和子标题相关联:

def scrape_article(d):
   return {'link':d.a['href'], 'title':d.span.text, 'tags':d.find('div', {'class':'article-name-tags'}).text, 
        'authors':[i.text for i in d.find_all('span', {'class':'entryAuthor'})], 'citation':d.find('div', {'class':'art_meta citation'}).text}

import requests, re, collections
from bs4 import BeautifulSoup as soup
d = soup(requests.get('https://ajph.aphapublications.org/toc/ajph/108/8').text, 'html.parser')
objs = d.find_all(re.compile('h2|div'), {'class':re.compile(r'tocHeading\d*|\barticleEntry\b')})
new_data = [(a, list(b)) for a, b in itertools.groupby(objs, key=lambda x:x['class'][0] == 'articleEntry')]
result, h1, h2 = collections.defaultdict(dict), None, None
for a, b in new_data:
    if not a:
       h1, h2 = h1 if b[0]['class'][0] == 'tocHeading1' else b[0].text, b[0].text if b[0]['class'][0] == 'tocHeading1' else None if len(b) == 1 else b[1].text
    else:
       result[h1]['__nosub__' if h2 is None else h2] = [scrape_article(i) for i in b]

输出:

{'AJPH EDITOR’S CHOICE': {'__nosub__': [{'link': '/doi/10.2105/AJPH.2018.304545', 'title': 'Venturing Beyond the Binary Sexual Health Interview', 'tags': 'Screening, Sexual Health, Lesbian/Gay/Bisexual/Transgender Persons, Gender', 'authors': ['Steffie Goodman', ''], 'citation': '108(8), pp. 965–965'}]}, 'AJPH GLOBAL NEWS': {'__nosub__': [{'link': '/doi/10.2105/AJPH.2018.304562', 'title': 'AJPH Global News', 'tags': '', 'authors': [], 'citation': '108(8), pp. 966–966'}, {'link': '/doi/10.2105/AJPH.2018.304576', 'title': 'News From The Nation’s Health', 'tags': '', 'authors': [], 'citation': '108(8), pp. 967–967'}]}, 'AJPH EDITORIALS': {'DRUG ARRESTS': [{'link': '/doi/10.2105/AJPH.2018.304575', 'title': 'Racial Inequities in Drug Arrests: Treatment in Lieu of and After Incarceration', 'tags': "Other Race/Ethnicity, Substance Use, Men's Health, Prevention, Health Law, Race/Ethnicity", 'authors': ['Barbara Ferrer', ' and ', 'John M. Connolly', ''], 'citation': '108(8), pp. 968–969'}], 'PRISONS & LGBT': [{'link': '/doi/10.2105/AJPH.2018.304537', 'title': 'Identifying and Ameliorating Lesbian, Gay, Bisexual, and Transgender Health Disparities in the Criminal Justice System', 'tags': 'Health Care Facilities/Services, Human Rights, Community Health, Lesbian/Gay/Bisexual/Transgender Persons', 'authors': ['Kami A. Kosenko', ' and ', 'Elizabeth A. Nelson', ''], 'citation': '108(8), pp. 970–971'}], 'INDOOR TANNING': [{'link': '/doi/10.2105/AJPH.2018.304521', 'title': 'The Story Behind the Sharp Decline in US Tanning Bed Rates', 'tags': 'Prevention, Child and Adolescent Health, Epidemiology, Health Policy, Other Child and Adolescent Health', 'authors': ['Alan C. Geller', ''], 'citation': '108(8), pp. 971–973'}], 'ALCOHOL': [{'link': '/doi/10.2105/AJPH.2018.304522', 'title': 'Preventing Risk for “Deaths of Despair” Among American Indian Youths: Unanswered Questions for Future Research', 'tags': 'Substance Use, Alcohol, Prevention, Child and Adolescent Health, Race/Ethnicity, Community Health, Health Promotion, Other Child and Adolescent Health, Native Americans', 'authors': ['Kelli A. Komro', ''], 'citation': '108(8), pp. 973–974'}], 'HOUSING AND ASTHMA': [{'link': '/doi/10.2105/AJPH.2018.304544', 'title': 'Subsidized Housing and Health: Time for a Multidisciplinary Approach', 'tags': 'Environment, Housing and Health', 'authors': ['Shakira F. Suglia', ''], 'citation': '108(8), pp. 975–976'}], 'VACCINES': [{'link': '/doi/10.2105/AJPH.2018.304538', 'title': 'History Lesson: Vaccine Trials in the Classroom', 'tags': 'Immunization/Vaccines, Child and Adolescent Health, Ethics, Other Child and Adolescent Health', 'authors': ['Jeffrey P. Baker', ''], 'citation': '108(8), pp. 976–977'}], 'SUNSHINE ACT': [{'link': '/doi/10.2105/AJPH.2018.304520', 'title': 'Extending the Sunshine Act From Physicians to Patient Advocacy Organizations', 'tags': 'Government, Health Financing, Insurance, Health Law, Socioeconomic Factors, Health Policy, Ethics', 'authors': ['Genevieve P. Kanter', ''], 'citation': '108(8), pp. 978–979'}], 'DENTAL CARIES': [{'link': '/doi/10.2105/AJPH.2018.304539', 'title': 'Wanted: Less Prevalence of and More Data on Early Childhood Caries', 'tags': 'Global Health, Child and Adolescent Health, Socioeconomic Factors, Statistics/Evaluation/Research, Dental/Oral Health, Surveillance, Other Child and Adolescent Health', 'authors': ['Cynthia A. Tschampl', ''], 'citation': '108(8), pp. 980–981'}], 'SELF-INJURY IN ADOLESCENTS': [{'link': '/doi/10.2105/AJPH.2018.304550', 'title': 'Nonsuicidal Self-Injury: A Neglected Public Health Problem Among Adolescents', 'tags': 'Mental Health, Screening, Prevention, Child and Adolescent Health, Adolescent Health, Epidemiology, Injury/Emergency Care/Violence', 'authors': ['Nicholas J. Westers', ' and ', 'Alison J. Culyba', ''], 'citation': '108(8), pp. 981–983'}], 'AUSTERITY IN SPAIN': [{'link': '/doi/10.2105/AJPH.2018.304507', 'title': 'Short-Term Adverse Effects of Austerity Policies on Mortality Rates: What Could Their Real Magnitude Be?', 'tags': 'Chronic Disease, Government, Other Chronic Disease, Health Financing, Insurance, Epidemiology, Health Policy', 'authors': ['Cristina Hernández-Quevedo', ', ', 'Beatriz G. Lopez-Valcarcel', ' and ', 'Miquel Porta', ''], 'citation': '108(8), pp. 983–985'}], 'PUBLIC HEALTH OF CONSEQUENCE': [{'link': '/doi/10.2105/AJPH.2018.304543', 'title': 'Making the Invisible Causes of Population Health Visible: A Public Health of Consequence, August 2018', 'tags': 'Epidemiology, Statistics/Evaluation/Research, Writing/Reviewing/Publishing, Other Statistics/Evaluation/Research', 'authors': ['Sandro Galea', ' and ', 'Roger D. Vaughan', ''], 'citation': '108(8), pp. 985–986'}]}, 'AJPH CRIMINAL JUSTICE': {'DRUG ARRESTS': [{'link': '/doi/10.2105/AJPH.2018.304445', 'title': 'Racial/Ethnic Disparities in Arrests for Drug Possession After California Proposition 47, 2011–2016', 'tags': 'Substance Use, Government, Drugs, Social Science, Race/Ethnicity', 'authors': ['Alyssa C. Mooney', ', ', 'Eric Giannella', ', ', 'M. Maria Glymour', ', ', 'Torsten B. Neilands', ', ', 'Meghan D. Morris', ', ', 'Jacqueline Tulsky', ' and ', 'May Sudhinaraset', ''], 'citation': '108(8), pp. 987–993'}], 'PRISONS & LGBT': [{'link': '/doi/10.2105/AJPH.2018.304500', 'title': 'Incarceration as a Health Determinant for Sexual Orientation and Gender Minority Persons', 'tags': 'Social Science, Lesbian/Gay/Bisexual/Transgender Persons', 'authors': ['Valerio Baćak', ', ', 'Kate Thurman', ', ', 'Katie Eyer', ', ', 'Rubab Qureshi', ', ', 'Jason D.P. Bird', ', ', 'Luis M. Rivera', ' and ', 'Suzanne A. Kim', ''], 'citation': '108(8), pp. 994–999'}], 'HUMAN PAPILLOMAVIRUS & JAIL': [{'link': '/doi/10.2105/AJPH.2018.304499', 'title': 'Human Papillomavirus Vaccine Knowledge and Intention Among Adult Inmates in Kansas, 2016–2017', 'tags': 'Chronic Disease, Cancer, Health Education, Immunization/Vaccines, Infections, Other Infections, Community Health, Health Promotion', 'authors': ['Molly Allison', ', ', 'Brynne Musser', ', ', 'Catherine Satterwhite', ', ', 'Kevin Ault', ', ', 'Patricia Kelly', ' and ', 'Megha Ramaswamy', ''], 'citation': '108(8), pp. 1000–1002'}], 'OPIOIDS': [{'link': '/doi/10.2105/AJPH.2018.304551', 'title': 'Baltimore Citywide Engagement of Emergency Departments to Combat the Opioid Epidemic', 'tags': 'Substance Use, Drugs, Public Health Practice', 'authors': ['Shelly Choo', ' and ', 'Leana S. Wen', ''], 'citation': '108(8), pp. 1003–1005'}], 'SOCIAL BOTS': [{'link': '/doi/10.2105/AJPH.2018.304512', 'title': 'Could Social Bots Pose a Threat to Public Health?', 'tags': 'Media, Prevention', 'authors': ['Jon-Patrick Allem', ' and ', 'Emilio Ferrara', ''], 'citation': '108(8), pp. 1005–1006'}], 'LONG-ACTING REVERSIBLE CONTRACEPTIVES': [{'link': '/doi/10.2105/AJPH.2018.304523', 'title': 'Long-Acting Reversible Contraception: A Silver Bullet Solution for Unintended Pregnancy?', 'tags': "Pregnancy, Sexual Health, Prevention, Women's Health, Health Policy, Maternal and Infant Health", 'authors': ['Adam Thomas', ' and ', 'Quentin C. Karpilow', ''], 'citation': '108(8), pp. 1007–1008'}], 'INFOVEILLANCE': [{'link': '/doi/10.2105/AJPH.2018.304497', 'title': 'Toward Real-Time Infoveillance of Twitter Health Messages', 'tags': 'Media, Social Science, Statistics/Evaluation/Research, Surveillance, Other Statistics/Evaluation/Research', 'authors': ['Jason B. Colditz', ', ', 'Kar-Hai Chu', ', ', 'Sherry L. Emery', ', ', 'Chandler R. Larkin', ', ', 'A. Everette James', ', ', 'Joel Welling', ' and ', 'Brian A. Primack', ''], 'citation': '108(8), pp. 1009–1014'}]}, 'AJPH HISTORY': {'VACCINES': [{'link': '/doi/10.2105/AJPH.2018.304423', 'title': 'Human Experimentation in Public Schools: How Schools Served as Sites of Vaccine Trials in the 20th Century', 'tags': '', 'authors': ['Will D. Schupmann', ''], 'citation': '108(8), pp. 1015–1022'}], 'INTELLECTUALS': [{'link': '/doi/10.2105/AJPH.2018.10881023', 'title': 'The Responsibility of Intellectuals', 'tags': '', 'authors': [], 'citation': '108(8), pp. 1023–1024'}, {'link': '/doi/10.2105/AJPH.2018.304465', 'title': 'Noam Chomsky (1928–), Fierce and Formidable Critic of the Vietnam War', 'tags': '', 'authors': ['Theodore Brown', ''], 'citation': '108(8), pp. 1025–1025'}]}, 'AJPH POLICY': {'SUNSHINE ACT': [{'link': '/doi/10.2105/AJPH.2018.304467', 'title': 'Industry Support of Patient Advocacy Organizations: The Case for an Extension of the Sunshine Act Provisions of the Affordable Care Act', 'tags': 'Health Law, Health Policy, Ethics', 'authors': ['Matthew S. McCoy', ''], 'citation': '108(8), pp. 1026–1030'}]}, 'AJPH RESEARCH': {'SUBSTANCE USE': [{'link': '/doi/10.2105/AJPH.2018.304446', 'title': 'Substance Use Among Lesbian, Gay, Bisexual, and Questioning Adolescents in the United States, 2015', 'tags': 'Substance Use, Alcohol, Drugs, Epidemiology', 'authors': ['Theodore L. Caputi', ', ', 'Laramie R. Smith', ', ', 'Steffanie A. Strathdee', ' and ', 'John W. Ayers', ''], 'citation': '108(8), pp. 1031–1034'}], 'ALCOHOL': [{'link': '/doi/10.2105/AJPH.2018.304447', 'title': 'Prevention of Underage Drinking on California Indian Reservations Using Individual- and Community-Level Approaches', 'tags': 'Substance Use, Alcohol, Prevention, Child and Adolescent Health, Race/Ethnicity, Community Health, Minority Children, Other Child and Adolescent Health, Native Americans', 'authors': ['Roland S. Moore', ', ', 'David A. Gilder', ', ', 'Joel W. Grube', ', ', 'Juliet P. Lee', ', ', 'Jennifer A. Geisler', ', ', 'Bettina Friese', ', ', 'Daniel J. Calac', ', ', 'Laura J. Finan', ' and ', 'Cindy L. Ehlers', ''], 'citation': '108(8), pp. 1035–1041'}], 'SELF-INJURY IN ADOLESCENTS': [{'link': '/doi/10.2105/AJPH.2018.304470', 'title': 'Nonsuicidal Self-Injury Among a Representative Sample of US Adolescents, 2015', 'tags': 'Mental Health, Child and Adolescent Health, Adolescent Health, Epidemiology, Injury/Emergency Care/Violence, Gender, Other Child and Adolescent Health', 'authors': ['Martin A. Monto', ', ', 'Nick McRee', ' and ', 'Frank S. Deryck', ''], 'citation': '108(8), pp. 1042–1048'}], 'SEX WORKERS': [{'link': '/doi/10.2105/AJPH.2018.304455', 'title': 'Childhood Experiences of Sexual Violence, Pregnancy, and Marriage Associated With Child Sex Trafficking Among Female Sex Workers in Two US–Mexico Border Cities', 'tags': "Global Health, Child and Adolescent Health, Women's Health, Injury/Emergency Care/Violence", 'authors': ['Sabrina C. Boyce', ', ', 'Kimberly C. Brouwer', ', ', 'Daniel Triplett', ', ', 'Argentina E. Servin', ', ', 'Carlos Magis-Rodriguez', ' and ', 'Jay G. Silverman', ''], 'citation': '108(8), pp. 1049–1054'}], 'WALKING SUPPORT': [{'link': '/doi/10.2105/AJPH.2018.304449', 'title': 'Community and Street-Scale Supports for Walking in the US Virgin Islands Before the 2017 Hurricanes', 'tags': 'Environment, Prevention, Other Environment, Epidemiology, Community Health, Exercise/Physical Activity, Health Promotion', 'authors': ['John D. Omura', ', ', 'Emily N. Ussery', ', ', 'Susan A. Carlson', ', ', 'Kathleen Arnold-Lewis', ', ', 'John Orr', ', ', 'Dana Olzenak McGuire', ', ', 'Lillianne Lewis', ', ', 'Prabasaj Paul', ', ', 'Erin L. Peterson', ', ', 'Janet E. Fulton', ' and ', 'Esther M. Ellis', ''], 'citation': '108(8), pp. 1055–1058'}], 'HOUSING AND ASTHMA': [{'link': '/doi/10.2105/AJPH.2018.304468', 'title': 'Subsidized Housing and Adult Asthma in Boston, 2010–2015', 'tags': 'Respiratory Health, Asthma, Environment, Housing and Health, Statistics/Evaluation/Research, Surveillance', 'authors': ['Amar J. Mehta', ', ', 'Daniel P. Dooley', ', ', 'John Kane', ', ', 'Margaret Reid', ' and ', 'Snehal N. Shah', ''], 'citation': '108(8), pp. 1059–1065'}], 'DENTAL CARIES': [{'link': '/doi/10.2105/AJPH.2018.304466', 'title': 'Prevalence and Data Availability of Early Childhood Caries in 193 United Nations Countries, 2007–2017', 'tags': 'Global Health, Other Health Service Delivery, Child and Adolescent Health, Epidemiology, Dental/Oral Health, Health Service Delivery, Other Child and Adolescent Health, Geography', 'authors': ['Maha El Tantawi', ', ', 'Morenike O. Folayan', ', ', 'Mohamed Mehaina', ', ', 'Ana Vukovic', ', ', 'Jorge L. Castillo', ', ', 'Balgis O. Gaffar', ', ', 'Arheiam Arheiam', ', ', 'Ola B. Al-Batayneh', ', ', 'Arthur M. Kemoli', ', ', 'Robert J. Schroth', ' and ', 'Gillian H.\u2009M. Lee', ''], 'citation': '108(8), pp. 1066–1072'}], 'SMOKING & PREGNANCY': [{'link': '/doi/10.2105/AJPH.2018.304469', 'title': 'Cigar and Marijuana Blunt Use Among Pregnant and Nonpregnant Women of Reproductive Age in the United States, 2006–2016', 'tags': "Pregnancy, Substance Use, Drugs, Tobacco, Other Tobacco, Child and Adolescent Health, Women's Health, Epidemiology, Tobacco and Health, Maternal and Infant Health", 'authors': ['Victoria H. Coleman-Cowger', ', ', 'Wallace B. Pickworth', ', ', 'Robert A. Lordo', ' and ', 'Erica N. Peters', ''], 'citation': '108(8), pp. 1073–1075'}], 'HOMELESS CHILDREN': [{'link': '/doi/10.2105/AJPH.2018.304493', 'title': 'Trends in Homeless Children and Young Adults Seeking Shelter in a Boston Pediatric Emergency Department Following State Housing Policy Changes, 2011–2016', 'tags': 'Health Care Facilities/Services, Homelessness, Environment, Housing and Health, Child and Adolescent Health, Health Policy, Low-Income Children, Injury/Emergency Care/Violence', 'authors': ['Mia Kanak', ', ', 'Amanda Stewart', ', ', 'Robert Vinci', ', ', 'Shanshan Liu', ' and ', 'Megan Sandel', ''], 'citation': '108(8), pp. 1076–1078'}], 'DEAF CHILDREN': [{'link': '/doi/10.2105/AJPH.2018.304498', 'title': 'Influence of Hearing Loss on Child Behavioral and Home Experiences', 'tags': 'Child and Adolescent Health, Epidemiology, Statistics/Evaluation/Research, Disability, Surveys, Other Child and Adolescent Health', 'authors': ['Wyatte C. Hall', ', ', 'Dongmei Li', ' and ', 'Timothy D. V. Dye', ''], 'citation': '108(8), pp. 1079–1081'}], 'SMOKING CESSATION': [{'link': '/doi/10.2105/AJPH.2018.304492', 'title': 'Disparities in Smoking Cessation Assistance in US Primary Care Clinics', 'tags': 'Substance Use, Tobacco, Smoking Cessation, Other Tobacco, Socioeconomic Factors, Health Service Delivery', 'authors': ['Steffani R. Bailey', ', ', 'John Heintzman', ', ', 'R. Lorie Jacob', ', ', 'Jon Puro', ' and ', 'Miguel Marino', ''], 'citation': '108(8), pp. 1082–1090'}], 'AUSTERITY IN SPAIN': [{'link': '/doi/10.2105/AJPH.2018.304346', 'title': 'RETRACTED: Austerity Policies and Mortality in Spain After the Financial Crisis of 2008', 'tags': 'Government, Socioeconomic Factors', 'authors': ['Antonio Cabrera de León', ', ', 'Itahisa Marcelino Rodríguez', ', ', 'Fadoua Gannar', ', ', 'Arturo J. Pedrero García', ', ', 'Delia Almeida González', ', ', 'M. del Cristo Rodríguez Pérez', ', ', 'Buenaventura Brito Díaz', ', ', 'José Juan Alemán Sánchez', ' and ', 'Armando Aguirre-Jaime', ''], 'citation': '108(8), pp. 1091–1098'}], 'CALORIE LABELING': [{'link': '/doi/10.2105/AJPH.2018.304513', 'title': 'Compliance in 2017 With Federal Calorie Labeling in 90 Chain Restaurants and 10 Retail Food Outlets Prior to Required Implementation', 'tags': 'Nutrition/Food, Health Policy', 'authors': ['Lauren P. Cleveland', ', ', 'Denise Simon', ' and ', 'Jason P. Block', ''], 'citation': '108(8), pp. 1099–1102'}]}, 'AJPH LETTERS AND RESPONSES': {'HURRICANES': [{'link': '/doi/10.2105/AJPH.2018.304508', 'title': 'The US Virgin Islands: The Ninth Ward of 2017?', 'tags': 'Public Health Practice, Socioeconomic Factors, Health Service Delivery', 'authors': ['Richard F. Gillum', ''], 'citation': '108(8), pp. e1–e1'}, {'link': '/doi/10.2105/AJPH.2018.304509', 'title': 'Tuckson Responds', 'tags': '', 'authors': ['Reed V. Tuckson', ''], 'citation': '108(8), pp. e1–e1'}], 'SOCIAL WORK': [{'link': '/doi/10.2105/AJPH.2018.304540', 'title': 'Repositioning Social Work Into Population Health', 'tags': 'Other Health Service Delivery, Health Education, Mental Health, Public Health Practice, Health Professionals, Community Health, Health Service Delivery', 'authors': ['Rebecca Feinstein', ' and ', 'Hale Thompson', ''], 'citation': '108(8), pp. e2–e2'}, {'link': '/doi/10.2105/AJPH.2018.304541', 'title': 'Bachman Responds', 'tags': 'Public Health Practice, Socioeconomic Factors, Health Policy, Public Health Workers, Community Health, Health Reform', 'authors': ['Sara S. Bachman', ''], 'citation': '108(8), pp. e2–e3'}], 'C-WORD': [{'link': '/doi/10.2105/AJPH.2018.304547', 'title': 'A Clarification on Causal Questions: We Ask Them More Often Than We Realize', 'tags': 'Epidemiology, Writing/Reviewing/Publishing', 'authors': ['Katrina L. Kezios', ' and ', 'Eleanor Hayes-Larson', ''], 'citation': '108(8), pp. e4–e4'}, {'link': '/doi/10.2105/AJPH.2018.304546', 'title': 'Calculating Versus Estimating Causal Effects', 'tags': 'Epidemiology', 'authors': ['Michael J. Green', ''], 'citation': '108(8), pp. e4–e5'}], 'SOCIAL IMPACT BONDS': [{'link': '/doi/10.2105/AJPH.2018.304548', 'title': 'Social Impact Bonds: A Promising Public–Private Partnership Model for Public Health', 'tags': 'Health Financing, Health Policy, Health Reform', 'authors': ['Samantha Iovan', ' and ', 'Paula M. Lantz', ''], 'citation': '108(8), pp. e6–e6'}, {'link': '/doi/10.2105/AJPH.2018.304549', 'title': 'Katz et al. Respond', 'tags': 'Government, Health Financing, Other Health Financing, Public Health Practice, Socioeconomic Factors, Health Policy, Health Reform', 'authors': ['Amy S. Katz', ', ', 'Patricia O’Campo', ', ', 'Benjamin Brisbois', ', ', 'Suzanne Zerger', ' and ', 'Stephen W. Hwang', ''], 'citation': '108(8), pp. e6–e8'}]}, 'AJPH ERRATA': {'__nosub__': [{'link': '/doi/10.2105/AJPH.2018.304457e', 'title': 'ERRATUM', 'tags': '', 'authors': [], 'citation': '108(8), pp. e9–e9'}, {'link': '/doi/10.2105/AJPH.108.S2.S50e', 'title': 'ERRATUM', 'tags': '', 'authors': [], 'citation': '108(8), pp. e10–e10'}]}, 'OTHER DEPARTMENTS': {'__nosub__': [{'link': '/doi/10.2105/AJPH.2018.10881103', 'title': 'Marketplace', 'tags': '', 'authors': [], 'citation': '108(8), pp. 1103–1103'}, {'link': '/doi/10.2105/AJPH.2018.10881104', 'title': 'Career Opportunities', 'tags': '', 'authors': [], 'citation': '108(8), pp. 1104–1104'}]}}

此解决方案添加了一个__nosub__键来代替缺少的子标题。例如AJPH GLOBAL NEWS是没有任何子标题的标题。因此,其子文章​​文章AJPH Global NewsNews From The Nation’s Health存储在__nosub__下,而AJPH EDITORIALS的所有子标题下都有内容:['DRUG ARRESTS', 'PRISONS & LGBT', 'INDOOR TANNING', 'ALCOHOL', 'HOUSING AND ASTHMA', 'VACCINES', 'SUNSHINE ACT', 'DENTAL CARIES', 'SELF-INJURY IN ADOLESCENTS', 'AUSTERITY IN SPAIN', 'PUBLIC HEALTH OF CONSEQUENCE']