dimanche 7 octobre 2018

"if" and "if not" in python acting differently in linux and windows machines

Following is a chunk of code:

price_tag = soup.find("p", attrs={"class": "a_class"})

if not price_tag.find(class_="original-price"):
    price = price_tag.text.strip().replace("\n", "").split(" ")[1]
else:
    price = price_tag.find("strike", attrs={"class": "op"}).text

In my windows PC this works fine but in a *nix (using Pythonanywhere) this works copletely opposite and to get the right result I have to remove the 'not' after 'if'.

(This is part of a scrapping script using beautiful soup. This checks whether the tag exist or not.)

Any reason and solution? (Please ask if any supporting information is necessary.)

Aucun commentaire:

Enregistrer un commentaire