Я пытаюсь загрузить файлы csv, которые заканчиваются определенными c символами «VX.csv» по этой ссылке:
https://www.cboe.com/products/futures/market-data/historical-data-archive
Вот код, который я адаптировал из другого аналогичного вопроса:
# Import Key Modules
from bs4 import BeautifulSoup
import requests
import urllib.request
url = 'https://www.cboe.com/products/futures/market-data/historical-data-archive'
def scraper(url):
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html)
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
href = (tag.get('href', None))
if href.endswith("VX.csv"):
csv_url = urlparse.urljoin(url, href)
# ... do something with the csv file....
contents = urllib.urlopen(csv_url).read()
print("csv file size=", len(contents))
break # we only needed this one file, so we end the loop.
scraper(url)
Я выдает следующую ошибку:
AttributeError: 'NoneType' object has no attribute 'endswith'
Я не уверен, где я ошибаюсь. У кого-нибудь есть подсказки?