如何修复AttributeError: ResultSet对象没有'get_text'属性问题——GitHub 3D主题高星仓库爬取报错排查
Hey there! That AttributeError makes total sense once you break it down:
When you use find_all(), BeautifulSoup returns a ResultSet—which is basically a list of all the matching tags you found. You can't call .get_text() on the entire list directly, because that method only works on individual tag elements, not collections of them.
Here's how to fix it:
Instead of trying to call get_text() on the whole star_tags list, loop through each tag in the list and process them one by one. You can use a list comprehension for a clean, concise solution:
# Bulk process all star count tags star_counts = [parse_star_count(tag.get_text().strip()) for tag in star_tags]
If you prefer a more explicit loop (great for debugging or adding extra steps), this works too:
star_counts = [] for tag in star_tags: # Extract and clean the star text from each individual tag star_text = tag.get_text().strip() # Convert to numerical count using your function count = parse_star_count(star_text) star_counts.append(count)
Either way, this will iterate over every <span> tag in your star_tags ResultSet, extract its text, run it through your parse_star_count function, and collect all the numerical star counts into a list. You can then print or use star_counts to see all the values!
内容的提问来源于stack exchange,提问作者S0L

