Skip to content

Instantly share code, notes, and snippets.

@smukkejohan
Created February 4, 2016 13:28
Show Gist options
  • Select an option

  • Save smukkejohan/4af32c90d28d56570a2e to your computer and use it in GitHub Desktop.

Select an option

Save smukkejohan/4af32c90d28d56570a2e to your computer and use it in GitHub Desktop.
debt clock scraper
from bs4 import BeautifulSoup
import requests
""" Extract debt from alt tag in img
<tr><td align="center"><img alt="$ 1 8 , 9 9 6 , 2 2 2 , 5 4 2 , 0 5 2 . 9 3 " height="41" src="debtiv.gif" width="421"/></td></tr>
"""
req = requests.get("http://brillig.com/debt_clock/", verify=False)
soup = BeautifulSoup(req.text, "html.parser")
debtStr = soup.find('img', attrs={'src':'debtiv.gif'})["alt"]
debtStr = debtStr.replace(" ", "")
debtStr = debtStr.replace(",", "")
debtStr = debtStr.replace("$", "")
debtFloat = float(debtStr)
print("US depth is now: $" + debtStr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment