Snagging Gold and Silver from with Python

If you’re keen on diversifying your investment portfolio with precious metals in physical form, you probably always look for the best deals and try to avoid broker fees. Traditionally, I’ve leaned on for such purchases. It’s a household name for precious metal investors, offering a wide range of metals at competitive prices. Yet, something caught my eye recently— has quietly entered the market of gold and silver bars and coins.

Costco’s offerings are roughly 5% cheaper than what you’d find on APMEX. When we’re talking about a large purchase, that discount is not just pennies; it’s a significant saving. But there’s a catch—Costco’s stock is as elusive. Every time you check, those sought-after bars and coins are out of stock.

I saw this as a perfect opportunity to blend two of my passions: coding and investing. The result? A Python script designed to scour Costco’s website for stock availability.

This script uses BeautifulSoup to parse Costco’s product listings, filtered by our specific keywords like ‘gold bar’, ‘gold coin’, ‘silver coin’, and ‘silver bar’. It cleverly dodges the limitations set by web servers on frequent requests by rotating through different user agents. So, every time it runs, the server perceives it as a new visitor.

By specifying both positive keywords (what we want) and negative keywords (what we don’t want, such as ‘necklace’, ‘plated’, etc.), the script filters through the clutter, presenting only the relevant links. And it does so by checking both the product availability and ensuring it matches our search criteria precisely.

Here is the code

Here is the code:

Leave a Reply