Beautifulsoup: 检索 table 中的特定值
Beautifulsoup: Retrieve specific value in table
我想检索此网页上 'Annual Report Expense Ratio (net):' 旁边的值:
http://finance.yahoo.com/q/pr?s=NCHAX+Profile
我正在使用库 beautifulSoup 和请求。到目前为止我的代码是:
from bs4 import BeautifulSoup
import requests
expenseRatioURL = 'http://finance.yahoo.com/q/pr?s=NCHAX+Profile'
rawHTML = requests.get(expenseRatioURL)
soup = BeautifulSoup(rawHTML.content)
g_data = soup.findAll("table", {"class": "yfnc_datamodoutline1"})
g_data 是一个包含所有四个表的单元素数组。
type(g_data)
returns:
<class 'bs4.element.ResultSet'>
如何检索 'Annual Report Expense Ratio (net):' 旁边的百分比?
p = soup.find(text="Annual Report Expense Ratio (net):").parent.next_sibling.string
我想检索此网页上 'Annual Report Expense Ratio (net):' 旁边的值:
http://finance.yahoo.com/q/pr?s=NCHAX+Profile
我正在使用库 beautifulSoup 和请求。到目前为止我的代码是:
from bs4 import BeautifulSoup
import requests
expenseRatioURL = 'http://finance.yahoo.com/q/pr?s=NCHAX+Profile'
rawHTML = requests.get(expenseRatioURL)
soup = BeautifulSoup(rawHTML.content)
g_data = soup.findAll("table", {"class": "yfnc_datamodoutline1"})
g_data 是一个包含所有四个表的单元素数组。
type(g_data)
returns:
<class 'bs4.element.ResultSet'>
如何检索 'Annual Report Expense Ratio (net):' 旁边的百分比?
p = soup.find(text="Annual Report Expense Ratio (net):").parent.next_sibling.string