title: Getting the closest previous element with this attribute using BeautifulSoup
body: <p>I am using BeautifulSoup to scrape metadata of  journal articles and need to retrieve each article's category. For example, let's use <a href="https://www.ajmc.com/journals/issue/2018/2018-vol24-n1/hospitalized-patients-and-family-members-preferences-for-realtime-transparent-access-to-their-hospital-records" rel="nofollow noreferrer">this article</a>. I've pasted the block of code I'm trying to parse below. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="landingDetailPluginDiv" class="p20"&gt;
    &lt;div class="article_category"&gt;CLINICAL&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/measuring-overuse-with-electronic-health-records-data"&gt;Measuring Overuse With Electronic Health Records Data&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Thomas Isaac, MD, MBA, MPH; Meredith B. Rosenthal, PhD; Carrie H. Colla, PhD; Nancy E. Morden, MD, MPH; Alexander J. Mainor, JD, MPH; Zhonghe Li, MS; Kevin H. Nguyen, MS; Elizabeth A. Kinsella, BA; and Thomas D. Sequist, MD, MPH&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_category"&gt;FROM THE EDITORS&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/the-health-information-technology-special-issue-has-it-become-a-mandatory-part-of-health-and-healthcare"&gt;The Health Information Technology Special Issue: Has IT Become a Mandatory Part of Health and Healthcare?&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Jacob Reider, MD&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_category"&gt;MANAGERIAL&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/bridging-the-digital-divide-mobile-access-to-personal-health-records-among-patients-with-diabetes"&gt;Bridging the Digital Divide: Mobile Access to Personal Health Records Among Patients With Diabetes&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Ilana Graetz, PhD; Jie Huang, PhD; Richard J. Brand, PhD; John Hsu, MD, MBA, MSCE; Cyrus K. Yamin, MD; and Mary E. Reed, DrPH&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_category"&gt;POLICY&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/electronic-health-record-superusers-and-underusers-in-ambulatory-care-practices"&gt;Electronic Health Record "Super-Users" and "Under-Users" in Ambulatory Care Practices&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Juliet Rumball-Smith, MBChB, PhD; Paul Shekelle, MD, PhD; and Cheryl L. Damberg, PhD&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/electronic-sharing-of-diagnostic-information-and-patient-outcomes"&gt;Electronic Sharing of Diagnostic Information and Patient Outcomes&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Darwyyn Deyo, PhD; Amir Khaliq, PhD; David Mitchell, PhD; and Danny R. Hughes, PhD&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/hospital-participation-in-meaningful-use-and-racial-disparities-in-readmissions"&gt;Hospital Participation in Meaningful Use and Racial Disparities in Readmissions&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Mark Aaron Unruh, PhD; Hye-Young Jung, PhD; Rainu Kaushal, MD, MPH; and Joshua R. Vest, PhD, MPH&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_category"&gt;WEB EXCLUSIVE&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/a-costeffectiveness-analysis-of-cardiology-econsults-for-medicaid-patients"&gt;A Cost-Effectiveness Analysis of Cardiology eConsults for Medicaid Patients&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Daren Anderson, MD; Victor Villagra, MD; Emil N. Coman, PhD; Ianita Zlateva, MPH; Alex Hutchinson, MBA; Jose Villagra, BS; and J. Nwando Olayiwola, MD, MPH&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/electronic-health-record-problem-lists-accurate-enough-for-risk-adjustment"&gt;Electronic Health Record Problem Lists: Accurate Enough for Risk Adjustment?&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Timothy J. Daskivich, MD, MSHPM; Garen Abedi, MD, MS; Sherrie H. Kaplan, PhD, MPH; Douglas Skarecky, BS; Thomas Ahlering, MD; Brennan Spiegel, MD, MSHS; Mark S. Litwin, MD, MPH; and Sheldon Greenfield, MD&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="article_title"&gt;&lt;a href="/journals/issue/2018/2018-vol24-n1/racialethnic-variation-in-devices-used-to-access-patient-portals"&gt;Racial/Ethnic Variation in Devices Used to Access Patient Portals&lt;/a&gt;&lt;/div&gt;
      &lt;div class="article_plus"&gt;Eva Chang, PhD, MPH; Katherine Blondon, MD, PhD; Courtney R. Lyles, PhD; Luesa Jordan, BA; and James D. Ralston, MD, MPH&lt;/div&gt;
      &lt;div class="fc"&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="borderBottom"&gt;&lt;/div&gt;
    &lt;div class="article_text"&gt;
      &lt;div class="current_article fl"&gt;
        &lt;div class="article_title"&gt;Currently Reading&lt;/div&gt;
        &lt;div class="article_title b"&gt;Hospitalized Patients' and Family Members' Preferences for Real-Time, Transparent Access to Their Hospital Records&lt;/div&gt;
        &lt;div class="article_plus b"&gt;Michael J. Waxman, MD, MPH; Kurt Lozier, MBA; Lana Vasiljevic, MS; Kira Novakofski, PhD; James Desemone, MD; John O'Kane, RRT-NPS, MBA; Elizabeth M. Dufort, MD; David Wood, MBA; Ashar Ata, MBBS, PhD; Louis Filhour, PhD, RN; &amp; Richard J. Blinkhorn
          Jr, MD&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see from the snippet, there are multiple  elements because each issue's table of contents is listed in a side panel on each article's web page. I only want to retrieve the article category specific to that article, so that means I need to retrieve the last <code>&lt;div class="article_category"&gt;</code> (in this case, WEB EXCLUSIVE) that comes before <code>&lt;div class="article_title b"&gt;</code> (Hospitalized Patients' and Family Members' Preferences for Real-Time, Transparent Access to Their Hospital Records). I am not sure if these elements should be treated as siblings.</p>