mardi 26 février 2019

How do I use and if statement based around the results of data in html while using python?

I am attempting to label items in a csv file based on contents in an html which is being scraped using BeautifulSoup. For some items, more information is required to fulfill what is needed to be presented in said csv file.

I am trying to use and if statement to determine what to label something as in the csv file.

Here is the code:

                if prodictid is 'Bonus':
                        productname = ((container["data-product"]) + " Bonus Edition")
                else:
                        productname = (container["data-product"])

and here is the html. You can see where it says bonus, that is what I have as productid:

<span class="highlight">Bonus</span>

The code later on prints everything to the csv file without adding " Bonus Edition" even when productid is "Bonus".

Is there something I am missing? My current theory is that I am not having it check the string properly, but I do not know where to go from there or if that is even the case.

Aucun commentaire:

Enregistrer un commentaire