以下のサイトから定期的にCSVファイルを取り込もうとしていますが、URLを指定すると、一定のタイミングで変更するため、beautiful soupを使用し、ある年月のCSVのURLを取得ができません。
以下のような、動的サイト?からXPathを取得する方法をご教授ください。
https://www.cmegroup.com/ja/trading/interest-rates/countdown-to-fomc.html
"
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
import urllib.request, urllib.parse, urllib.error
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
}
url = "https://www.cmegroup.com/trading/interest-rates/countdown-to-fomc.html"
req = requests.get(url, headers=header)
soup = BeautifulSoup(req.content, "lxml")
print('a')
for i_a in soup.findAll('a'):
title = i_a.get("title")
href = i_a.get("href")
print(title,href)
if "Download Federal Reserve meeting history for 14 Dec 2022" in href:
print(title)
"

回答1件
あなたの回答
tips
プレビュー