Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用BeautifulSoup4和Python 3解析html表_Python_Html_Parsing_Beautifulsoup - Fatal编程技术网

使用BeautifulSoup4和Python 3解析html表

使用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

我正试图从雅虎财经获取某些财务数据。特别是在这种情况下,单个收入编号(类型: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_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)