使用BeautifulSoup4和Python 3解析html表
我正试图从雅虎财经获取某些财务数据。特别是在这种情况下,单个收入编号(类型:double) 这是我的密码:使用BeautifulSoup4和Python 3解析html表,python,html,parsing,beautifulsoup,Python,Html,Parsing,Beautifulsoup,我正试图从雅虎财经获取某些财务数据。特别是在这种情况下,单个收入编号(类型:double) 这是我的密码: 从urllib.request导入urlopen 从bs4导入BeautifulSoup 搜索URL=”http://finance.yahoo.com/q/ks?s=AAPL" f=urlopen(搜索URL) html=f.read() soup=BeautifulSoup(html,“html.parser”) 收益=soup.find(“div”,“class”:“yfnc_ta
从urllib.request导入urlopen
从bs4导入BeautifulSoup
搜索URL=”http://finance.yahoo.com/q/ks?s=AAPL"
f=urlopen(搜索URL)
html=f.read()
soup=BeautifulSoup(html,“html.parser”)
收益=soup.find(“div”,“class”:“yfnc_tabledata1”,“id”:“yui_3_9_1_8_1456172462911_38”))
打印(收入)
使用revenue(ttm):
文本找到td
元素并获取:
打印234.99B
revenue = soup.find("td", text="Revenue (ttm):").find_next_sibling("td").text
print(revenue)