I have the a bunch of html data looking like this:
<div id="productplacementlist_1" class="c-channel-placement-content">
<h3 class="c-subheading-6">TITLE1 EXAMPLE</h3>
The "div id" is unique for every class, the value behind the "_" changes to 2, 3, 4, etc. I want the content (string, text) for every h3 class. So I use:
start = soup.find("h3").string
This works great for me, but only for the first "h3" item - when I print it out, I get the content, e.g. in this case:
Output:
"TITLE 1 EXAMPLE"
I have 191 "strings" from h3 tags I want to save, each in a single value. So "start" is my starting point, from there, I jump to the next item with:
s2 = start.find_next("h3").string
This works great, I get the next item. But I think it's not the best way to manually create a new "start point" (like s2 here) for 191 items.
So I simply want a loop, starting from "start", then jump to s2, save this (automatically in the background) as s3, then jump to the next item and so on - the loop should stop on the last h3 tag.
OR
Other way is to get all h3 tags with one search, with the following command:
search2 = soup.find_all("h3", {"class": "c-subheading-6"})
Output:
<h3 class="c-subheading-6>"TITLE 1 EXAMPLE</h3>
<h3 class="c-subheading-6>"TITLE 2 EXAMPLE</h3>
This would be okay too, but I need to find a way to store the string (text only) of every h3 class in a single value, not in a list.