级别2股票报价.com提供免费的实时顶级书籍报价,我想用python捕捉使用BeautifulSoup。问题是,尽管我可以在浏览器检查器中看到实际的数据值,但我无法将这些值刮到python中。你知道吗
BeautifulSoup返回所有数据行,每个数据元素为空。Pandas为每个数据元素返回一个带有NaN的数据帧。你知道吗
import bs4 as bs
import urllib.request
import pandas as pd
symbol = 'AAPL'
url = 'https://markets.cboe.com/us/equities/market_statistics/book/'+ symbol + '/'
page = urllib.request.urlopen(url).read()
soup = bs.BeautifulSoup(page,'lxml')
rows = soup.find_all('tr')
print(rows)
for tr in rows:
td = tr.find_all('td')
row =(i.text for i in td)
print(row)
#using pandas to get dataframe
dfs = pd.read_html(url)
for df in dfs:
print(df)
有没有比我更有经验的人能告诉我如何提取这些数据? 谢谢!你知道吗
页面是动态的。您要么需要使用Selenium来模拟浏览器,让页面在获取html之前呈现,要么直接从jsonxhr获取数据。你知道吗
输出:
相关问题 更多 >
编程相关推荐