【发布时间】:2020-02-16 01:20:33
【问题描述】:
我正在尝试抓取网页(“coinmarketcap”)。我正在抓取所有加密货币从 2013 年到 2019 年 10 月(开盘价、最高价、最低价、收盘价、市值、成交量)的数据。
for j in range (0,name_size):
url = ("https://coinmarketcap.com/currencies/" + str(name[j]) + "/historical-data/?start=20130429&end=20191016")
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page, 'html.parser')
priceDiv = soup.find('div', attrs={'class':'table-responsive'})
rows = priceDiv.find_all('tr')
问题是某些 url 不存在。我不知道如何跳过这些。你能帮帮我吗?
【问题讨论】:
-
使用
try和except处理异常,编写在try和except异常中引发错误的部分,并且什么都不做,写pass to ignore except 或者你可以编写代码当出现错误时会做一些事情 -
你能举一个有效的 url 和失败的 url 的例子吗?
标签: python beautifulsoup web-crawler screen-scraping