isinstance not working correctly with beautifulsoup(NameError)
问题 I'm using isinstance to select some html tags and passing them to a Beautifulsoup function. The problem is I keep getting NameErrors from what should be perfectly executable code. def horse_search(tag): return (tag.has_attr('href') and isinstance(tag.previous_element, span)) ... for tag in soup.find_all(horse_search): print (tag) NameError: global name 'span' is not defined Also I'm getting errors from the example code in the documentation of Beautifulsoup using isinstance in conjunction with