Skip to content

Instantly share code, notes, and snippets.

@oskarsh
Created June 19, 2018 09:48
Show Gist options
  • Save oskarsh/c94812fda759d96a0ffa9bfc7168ad72 to your computer and use it in GitHub Desktop.
Save oskarsh/c94812fda759d96a0ffa9bfc7168ad72 to your computer and use it in GitHub Desktop.
This will work like the coincrawler in a more general way using the BeautifulSoup module.
import urllib.parse
import urllib.request
from bs4 import BeautifulSoup
from pprint import pprint
def urlReader(url):
print("")
print("fetching data from coinmarketcap.com")
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
respData = resp.read()
soup = BeautifulSoup(respData, 'html.parser')
return soup
def main():
url= 'http://coinmarketcap.com'
firstPrices=10
soup = urlReader(url)
i=0
dict={}
currencies=['Bitcoin', 'Ethereum', 'Bitcoin Cash', 'IOTA', 'Ripple', 'Dash', 'Litecoin', 'Bitcoin Gold', 'Monero', 'Cardano']
#Using soups.select to find the price
print("")
print("writing dictonary...")
print("")
for price in soup.select('.price'):
#print first 10 statements
if i>=firstPrices:
break
dict[currencies[i]] = (price['data-usd'] + '$')
i = i + 1
pprint(dict)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment