R_i = alpha_i + beta_i * R_m + e_i
where the R_m is the return of the market. You can simply get the monthly return for a given stock and the S&P 500 as the market. Run a linear regression and the slope will be your beta.
Based on this post from Quantitative Finance from Stackexchange, the Beta calculated was based on the monthly return for the past three years. Comparing with our calculation in Python, the number lines up pretty well.
Note: I was using the close price, when using the open price, it was pretty close too. However, the beta calculated using high and low is pretty different from Yahoo Finance.