I am trying to create a float list from text derived from an HTML website, as i want to make an if statement later down the line that will show if the list has a price at my budget or lower. I am using find_all function from beautifulsoup4 to retrieve the text without any tags:
So far this is how my code is coming along:
import requests
from bs4 import BeautifulSoup
url = "https://starpets.gg/adopt-me/shop/pet/firefly/15292";
result = requests.get(url);
doc = BeautifulSoup(result.text, "html.parser")
tag = doc.find("span", itemprop = "price");
for price1 in tag:
print("Best price", price1.text);
print("-----");
tag = doc.find_all("div", class_ = "_text_j98bt_1 _text__size_m_j98bt_40 _text__weight_bold_j98bt_83 _text__style_normal_j98bt_95 _text__decoration_normal_j98bt_104 _content-price_1gow4_85");
for price2 in tag:
print(price2.text);
And these are the results (at the moment) i get from that:
Best price 1.36
-----
1.35 $
1.7 $
3.25 $
The reason there is two separate price variables is that the website uses two different tags for the price depending on the location of it, with the class tag being the one that has the majority of prices, and the amount of them is constantly changing.
However, if i try to print price2.text separately from the for price2 in tag: function, it only prints the very last price2.
I am really new to python and webscraping in general, so forgive me if the answer is obvious