Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6548011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:53:58+00:00 2026-05-25T11:53:58+00:00

I have 2 variables, one with ‘last volume’ and the other with ‘last issue’.

  • 0

I have 2 variables, one with ‘last volume’ and the other with ‘last issue’.

The HTML I am dealing with contains a list of all volumes and issues, most recent first.

I need to return the href links for all volumes and issues that are newer than what I have on file.

So using the below example, say my last volume is 13 and last issue is 1, I would need to return the href for vol 13, 2 and vol 14, 1.

I am having a hard time with this since the volume is on its own…

Here is what I have so far:

HTML:

<ul class="bobby">
<li><strong>Volume 14</strong></li>
<li class="">
<a href="/content/ben/cchts/2011/00000014/00000001" title="Issue 1, September 2011">Issue 1, September 2011</a>          
</li>
<li><strong>Volume 13</strong></li> 
<li class="">
<a href="/content/ben/cchts/2010/00000013/00000002" title="Issue 2, December 2010">Issue 2, December 2010</a>
</li>
<li class="">
<a href="/content/ben/cchts/2011/00000014/00000001" title="Issue 1, November 2011">Issue 1, November 2011</a>
</li>
</ul>

Script Snipped:

results = soup.find('ul', attrs={'class' : 'bobby'})

#temp until I get it reading from file
lastVol = '13'
#find the last volume
findlastVol = results.findNext('strong', text= re.compile('Volume ' + lastVol))

#temp until I get it reading from file
lastIss = '2'
#find the last issue
findlastIss = findlastVol.findNext('a', text= re.compile('Issue ' + lastIss))

So I can get to the tag for the last volume and issue on file, but I have had several failed attempts at traversing back up and stopping at the first issue…

Or starting at the top and traversing down until that volume and issue condition is met…

Can someone please give me some assistance? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:53:58+00:00Added an answer on May 25, 2026 at 11:53 am

    I think you are looking for findPrevious, which you could use this way:

    import BeautifulSoup
    import re
    
    content='''
    <ul class="bobby">
    <li><strong>Volume 14</strong></li>
    <li class="">
    <a href="/content/ben/cchts/2011/00000014/00000001" title="Issue 1, September 2011">Issue 1, September 2011</a>          
    </li>
    <li><strong>Volume 13</strong></li> 
    <li class="">
    <a href="/content/ben/cchts/2010/00000013/00000002" title="Issue 2, December 2010">Issue 2, December 2010</a>
    </li>
    <li class="">
    <a href="/content/ben/cchts/2011/00000014/00000001" title="Issue 1, November 2011">Issue 1, November 2011</a>
    </li>
    </ul>
    '''
    
    last_volume=13
    last_issue=1
    
    soup=BeautifulSoup.BeautifulSoup(content)
    results = soup.find('ul', attrs={'class' : 'bobby'})
    for a_string in results.findAll('a', text=re.compile('Issue')):
        volume=a_string.findPrevious(text=re.compile('Volume'))
        volume=int(re.search(r'(\d+)',volume).group(1))
        issue=int(re.search(r'(\d+)',a_string).group(1))
        href=a_string.parent['href']
        if (volume>last_volume) or (volume>=last_volume and issue>last_issue):    
            print(volume,issue,href)
    

    yields

    (14, 1, u'/content/ben/cchts/2011/00000014/00000001')
    (13, 2, u'/content/ben/cchts/2010/00000013/00000002')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two variables, one is called PaidThisMonth , and the other is called
In one servlet I have four variables. I want all those four variables to
In my init I have set some variables and one animate that uses those
We have FireSymfony that allows one to view the Symfony, PHP variables in a
I have two pages. First one we open with $_POST variables in its url,
I have a list of hclust objects resulting from slight variations in one variable
I have two variables, one with text, and another with patterns. And I want
I have some variables and I want to select the first one that evaluates
Does PHP have global variables that can be modified by one running script and
I have 2 datasources defined in my dataSource.groovy one is default dataSource { all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.