从Yahoo财务报表中提取数字,愿意通过Pay Pal支付一些钱 [英] Extracting Numbers from Yahoo Financial statement, willing to pay some money through Pay Pal

查看:126
本文介绍了从Yahoo财务报表中提取数字,愿意通过Pay Pal支付一些钱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python从Yahoo财务中提取财务数据. 下面有一个图像链接,该图像以圆圈显示了我要检索的数据.它具有数据表的组织,但是我不知道从图中所示的给定位置开始.

I am trying to extract financial data from yahoo finance using python. Below there is a link to an image that shows in circles which data I am trying to retrieve. It has the organization of the data table however I do not know where to begin with the givens shown in the picture.

这是我尝试从Yahoo Finance中提取的数字的代码位置的图像,带有表名和td代码.

This is the image of the code location of the numbers I'm trying to extract from yahoo finance, with the table name and td tickers.

我意识到我必须以某种方式使用td行情自动收录器来查找提取所需的数字,但是我不确定我需要实现哪些基本命令.

I realize that I must somehow use the td tickers to find the numbers that I need for the extraction however Im not sure what are the basics commands that I need to implement.

这是链接到数据示例我要抓的桌子

This is a link to an example of the the data table that I'm trying to scrape

推荐答案

您抓取的页面由JavaScript渲染,请求和urllib无法处理JavaScript.我建议您使用硒和BeautifulSoup提取数据. 这是禁用JavaScript的时间:

The page you scraped is rendered by JavaScript, requests and urllib can not handle JavaScript. I recommend you using selenium and BeautifulSoup to extract data. This is when JavaScript is disabled:

您想要的数据在此url中:

the data you wanted is in this url :

http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:AAPL&region=usa&culture=en-US&ops=clear&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=378724&callback=jsonp1482077238548&_=1482077239651

我把它放在bs4中,您可以自己获得数据:

i put it in the bs4, you can get the data by you own:

import requests, bs4, json

r = requests.get('http://financials.morningstar.com/ajax/ReportProcess4HtmlAjax.html?&t=XNAS:AAPL&region=usa&culture=en-US&ops=clear&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=378724&callback=jsonp1482077238548&_=1482077239651')

js = r.text.strip('jsonp1482077238548()')
html_str = json.loads(js)['result']
soup = bs4.BeautifulSoup(html_str, 'lxml')

退出:

<html>
 <body>
  <div id="baseline" style="display:none">
   <div>
    156508000000
   </div>
   <div>
    170910000000
   </div>
   <div>
    182795000000
   </div>
   <div>
    233715000000
   </div>
   <div>
    215639000000
   </div>
   <div>
    215639000000
   </div>
  </div>
  <div class="left ">
   <div class="r_xcmenu rf_table_left">
    <div class="rf_header ">
     <div class="lbl " currency="USD" fiscalyearend="September" fyenumber="9" id="unitsAndFiscalYear">
     </div>
    </div>
    <div class="rf_crow1" id="label_i1" style="_height:16px; _float:none;">
     <div class="lbl">
      Revenue
     </div>
     <div class="chart_contain_free" id="chart_i1">
      <div class="chart_icon">
      </div>
     </div>
    </div>

这篇关于从Yahoo财务报表中提取数字,愿意通过Pay Pal支付一些钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆