weston6142
weston6142

Reputation: 191

How to grab the contents in a beautiful soup tag list?

<a href="thisisaurl.html" data-id="7083608062" class="result-title hdrlnk">A table</a>

There is an entire webpage of these tags that I am trying the grab the text from. In this instance, it is "A table". So far I can get a list of these blocks of html like the one above using item_title = soup.findAll("a", "result-title") I can't seem to figure out how to narrow it down so I just have a list like ["A table", A chair", . . .] etc. from these blocks of html.

Any help would be greatly appreciated!

Upvotes: 0

Views: 97

Answers (1)

phil
phil

Reputation: 423

You can use the string property of a tag to get the string that's inside the tag.

items = [a_tag.string for a_tag in item_title]

Upvotes: 1

Related Questions