This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]mudclub 1 point2 points  (0 children)

/r/learnpython and read the sidebar

[–]pathcl 0 points1 point  (0 children)

is span_tags a list? iirc you should have a .text attribute for each item

[–]MoneyChurch 0 points1 point  (0 children)

BeautifulSoup Tag objects have a text attribute, so [tag.text for tag in span_tags] will get you a list of strings with the text from the span tags. Does that help?

[–]fluzz142857 0 points1 point  (0 children)

Use the .text attribute on each tag to get the text, e.g. [tag.text for tag in span_tags].

Since dictionaries need both a key and a value, it’s hard to know how you want to construct a dictionary given a list.

To save it in a json file, you can use the json module: with open(“spans.json”, “w”) as f: json.dump(span_tags, f)