Skip to content

Commit

Permalink
fix scraper (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
guptarohit authored Oct 3, 2020
1 parent 03d181a commit 8c256cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 1 addition & 8 deletions cryptocmd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,15 @@ def get_data(self, format="", verbose=False, **kwargs):
:param kwargs: Optional arguments that data downloader takes.
:return:
"""
if format:
data = tablib.Dataset()

if format not in data._formats:
raise tablib.UnsupportedFormat(
"Format {0} cannot be exported.".format(format)
)

self._download_data(**kwargs)

if verbose:
print(*self.headers, sep=", ")

for row in self.rows:
print(*row, sep=", ")
elif format:
data = tablib.Dataset()
data.headers = self.headers
for row in self.rows:
data.append(row)
Expand Down
10 changes: 6 additions & 4 deletions cryptocmd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ def get_coin_id(coin_code):
raw_data = pq(html)

coin_code = coin_code.upper()
data_table = raw_data("tbody")[0]

for _row in raw_data("tr")[1:]:
symbol = _row.cssselect("td.text-left.col-symbol")[0].text_content()
coin_id = _row.values()[0][3:]
for _row in data_table.findall("tr"):
symbol = _row.findall("td")[2].text_content()
coin_link = _row.findall("td")[1].find_class("cmc-link")[0]
coin_id = coin_link.values()[0].lstrip("/currencies/")[:-1]
if symbol == coin_code:
return coin_id
raise InvalidCoinCode("'{}' coin code is unavailable on coinmarketcap.com".format(coin_code))
Expand Down Expand Up @@ -140,7 +142,7 @@ def extract_data(html):

rows = []

for _row in raw_data("table tbody>tr"):
for _row in raw_data(".cmc-tab-historical-data table tbody>tr"):
row = [
_native_type(_replace(col.text_content().strip(), ",-*?"))
for col in _row.findall("td")
Expand Down

0 comments on commit 8c256cc

Please sign in to comment.