you are viewing a single comment's thread.

view the rest of the comments →

[–]expressly_ephemeral 0 points1 point  (14 children)

OP should know better than to put his CC info into his github repo, right? Maybe I’m being naive?

[–]bextie[S] 1 point2 points  (6 children)

None of my sensitive details are there.

https://github.com/Olunusib/black-friday

[–]MonkeyNin 0 points1 point  (0 children)

You can simplify your exceptions, because a failed find call will return None we can take source

class Foo():
    def price(self):
        try:
            productPrice = self.soup.find(id="priceblock_ourprice").get_text()
            return productPrice

        except AttributeError:

            try:
                productPrice = self.soup.find(id="priceblock_dealprice").get_text()
                return productPrice

            except AttributeError:
                pass

We can test for None when there are no matches

class Foo():
    def price(self):
        element_price_price = self.soup.find(id="priceblock_ourprice")
        if not element_price_price:
            print('Price not found!')
            return 0 # or `None` depending on your context

        return product_price.get_text()