dimanche 10 septembre 2017

Python 3 Help: If list contains "this text" then do something

I have a list (called "objects") and want to check if the first element in the list contains the text "You entered a valid number, but we are not able to show the tracking information for one of the following reasons: ".

I have tried a few different ways but keep getting a syntax issue. I'm not sure if it has to do with the colon in the text or if it is something else.

Portion of code below:

    objects = []
for each in Soup.find_all("fieldset"):
    each = each.get_text().split("\n") #split the ugly string up
    each = [each[1][-13:], each[5]] #grab the parts you want, rmv extra words
    objects.extend(each)

VaildSearchCheck = "You entered a valid number, but we are not able to show the tracking information for one of the following reasons: "

If VaildSearchCheck in objects:
    #Do Something

Aucun commentaire:

Enregistrer un commentaire