Bottom Page

Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 'soup.findAll()' help - Want to retrieve multiple attribute values

I am extremely new to python and am working on developing basic web crawlers. One data point I am interested in retrieving from a particular website is 'engagement'; however, when I inspect the webpage element, the HTML reveals that the engagement number has multiple attribute values depending upon how much it is being engaged with. For example, the element is 'span' and the attribute is 'class' but there are multiple attribute values associated with it ('hot', 'warm').

Here is my (partial) code:

for link in soup.findAll('span', {'class': 'warm' 'hot'}):
            views = link.string
If i choose just one, i do get some print out. However, I want to get the engagement data from every article I crawl.

Therefore, my question is this: How do I incorporate multiple attribute values into a single soup.findAll so that I don't clutter up my print out?

Thanks for the help!

I have also tried the following:

for link in soup.findAll('span', {'class': ['warm','hot']}):
            views = link.string
This doesn't produce any errors, but it doesn't print anything out
you second code is the one that should work.
Quote:soup.findAll('span', {'class': ['warm','hot']}):
Work your way backwards. Instead of printing out link.string, see what link actually contains. If link is empty then work you way backwards even more.

However is there an outer HTML tag that this is nested in, to grab each span element?

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to pass multiple values from one sample to nc variable? Baloch 0 95 Jun-01-2020, 09:27 PM
Last Post: Baloch
  Inserting values from multiple lists sqlite azulu 1 256 May-24-2020, 08:40 AM
Last Post: ibreeden
  UnUnloading values from multiple widgets in a container UGuntupalli 3 248 Apr-20-2020, 08:53 PM
Last Post: UGuntupalli
  The "FindAll" Error BadWhite 6 365 Apr-11-2020, 05:59 PM
Last Post: snippsat
  Beginner question: lxml's findall in an xml namespace aecklers 0 191 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Save all values to pandas of multiple classes jenniferruurs 0 260 Sep-13-2019, 12:10 PM
Last Post: jenniferruurs
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 521 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Try for multiple values bluethundr 1 574 Mar-07-2019, 09:04 PM
Last Post: bluethundr
  Get multiple values from function and total it. nirlep 5 784 Feb-05-2019, 06:54 AM
Last Post: nirlep
  Issue with re.findall alinaveed786 8 1,242 Oct-20-2018, 09:28 AM
Last Post: volcano63

Forum Jump:

Users browsing this thread: 1 Guest(s)