【发布时间】:2020-03-23 05:13:40
【问题描述】:
我最近编写了一个脚本,从网站 (https://www.cmegroup.com/trading/interest-rates/cleared-otc.html) 上抓取一些财务数据,以便跟踪项目交易量的变化。
但是,他们似乎稍微更改了 HTML,我的脚本不再工作。
我曾经使用它来从 'table20' 中获取值。
#Options for Chrome Driver (Selenium)
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Program Files\Anaconda\chromedriver\chromedriver.exe')
driver.get("https://www.cmegroup.com/trading/interest-rates/cleared-otc.html")
current_page = driver.page_source
#Grab all the information from website HTML
soup = BeautifulSoup(current_page, 'html.parser')
tbl = soup.find("div", {"id": "table20"})
但是,tbl 现在是一个“NoneType”,其中没有任何内容。
我也尝试了以下方法,但无济于事:
table_2 = soup.find(lambda tag: tag.name == 'table' and tag.has_attr('id') and tag['id'] == 'table20')
所以问题是,我如何为 table20 抓取所有这些货币值?
【问题讨论】:
标签: python web-scraping beautifulsoup