Created
February 4, 2016 13:28
-
-
Save smukkejohan/4af32c90d28d56570a2e to your computer and use it in GitHub Desktop.
debt clock scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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