Beautifulsoup:检索表中的特定值

时间:2015-04-07 21:14:35

标签: python web-scraping beautifulsoup

我想检索“年度报告费用率(净值)”旁边的值:'在这个网页上:

http://finance.yahoo.com/q/pr?s=NCHAX+Profile

我正在使用libaries beautifulSoup和request。到目前为止我的代码是:

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)

返回:

<class 'bs4.element.ResultSet'>

如何检索“年度报告费用率(净值)”旁边的百分比:&#39;?

1 个答案:

答案 0 :(得分:1)

p = soup.find(text="Annual Report Expense Ratio (net):").parent.next_sibling.string