geekpete / py-coinspot-api

A python library for the Coinspot API.
Other
15 stars 15 forks source link

BeautifulSoup price extraction #16

Open clixx-io opened 6 years ago

clixx-io commented 6 years ago

This is rough code, but it seems to work for getting prices. Something like this should be in the API if it isn't already.

-# import libraries import urllib2 from bs4 import BeautifulSoup

-# specify the url quote_page = "https://www.coinspot.com.au/buy/dgb"

-# query the website and return the html to the variable page hdr = {'User-Agent': 'Mozilla/5.0'} req = urllib2.Request(quote_page,headers=hdr) page = urllib2.urlopen(req)

-# parse the html using beautiful soup and store in variable soup soup = BeautifulSoup(page, "html.parser")

-# Take out the

of name and get its value name_box = soup.find('h1', attrs={'class': 'price-title'})

-# strip() is used to remove starting and trailing name = name_box.text.strip() print name