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

  • Home
  • SEARCH
  • 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 8256331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:50:08+00:00 2026-06-08T01:50:08+00:00

I have a html file which looks something similar to this : <html> …

  • 0

I have a html file which looks something similar to this :

<html>
...
<li class="not a user"> </li>
<li class="user">
 <a href="abs" ...> </a>
</li>
<li class="user">
 <a href="bss" ...> </a>
</li>
...
</html>

given the above input I want to parse the li tags with class=”user” and get the value of the href’s as output. is this possible using beautifulsoup in python ???

my solution was:

data="the above html code snippet"
soup=BeautifulSoup(data)
listset=soup("li","user")
for list in listset:
   attrib_value=[a['href'] for a in list.findAll('a',{'href':True})]

obviously i have an error somewhere that it only lists the attribute value for the last anchor tag’s href.

  • 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-06-08T01:50:09+00:00Added an answer on June 8, 2026 at 1:50 am

    Your code is fine. There are three elements in listset – and attrib_value gets overridden in each iteration of your loop, so at the end of the program, it only contains the href values from the last element of listset, which is bss.

    Try this instead to keep all values:

    attrib_value += [a['href'] for a in list.findAll('a',{'href':True})]
    

    and initialize attrib_value to the empty list before the loop (attrib_value = []).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file structure on my server that looks something like this: My
I have an HTML file which is launching an app if I open it
I currently have a huge HTML file which doesn't have line breaks and just
can anyone help? I have a simple html file which i am filling via
I have a HTML file upload field from which I'm reading the file name
Let's say I'm including a file which contains html. The html have characters as
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have a file which is combination of PHP and HTML. How can i
I have a JSON file which contains HTML content. I want to load it
I have written xml file which contains html tags as element like <component> <input

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.