0

I want to use python beautifulsoup to extract the class property name in a piece of html content. For example, <td><div class="na"></div></td>, "na" is the string I want to get, as sometimes the html content will switch to <td><div class="fail"></div></td> I want to catch the property changes from "na" to "fail" or from "fail" to "na", and report it.

Any ideas?

leiyc
  • 903
  • 11
  • 23
  • 1
    A BS element has a dictionary interface. Once you find a `
    `, just use a dictionary lookup: `soup.findAll('div')[0]['class']`.
    – DYZ Jan 25 '18 at 06:35
  • @DYZ, great thanks. It works. I did not catch this point in the document of beautifulsoup. does that mean soup.findAll('div')[0] is a dictionary type or has a function to override hash operation? – leiyc Jan 25 '18 at 06:55
  • soup.find('div')[0] is a navigable string object. – Ethan Henderson Jan 27 '18 at 00:33

0 Answers0