Pregunta

Hasta ahora tengo el siguiente código:

Dim wreqBalQtr As HttpWebRequest = WebRequest.Create("http://www.reuters.com/finance/stocks/incomeStatement/detail?stmtType=BAL&perType=INT&symbol=" & tickerValue)
wreqBalQtr.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"
wreqBalQtr.Method = "get"
Dim proxBalQtr As IWebProxy = wreqBalQtr.Proxy
proxBalQtr.Credentials = CredentialCache.DefaultCredentials
Dim documentBalQtr As New HtmlAgilityPack.HtmlDocument
Dim webBalQtr As New HtmlAgilityPack.HtmlWeb
webBalQtr.UseCookies = True
webBalQtr.PreRequest = New HtmlAgilityPack.HtmlWeb.PreRequestHandler(AddressOf onPreReq)
wreqBalQtr.CookieContainer = cookies
Dim resBalQtr As HttpWebResponse = wreqBalQtr.GetResponse()
documentBalQtr.Load(resBalQtr.GetResponseStream, True)
Dim TotalCurrentAssets = documentBalQtr.DocumentNode.SelectSingleNode("//table[@class='dataTable Financials']//tr[13]//td[3]")

Y el HTML es:

<table class="dataTable financials" cellspacing="1" cellpadding="0" width="100%">
  <tr>
    <th class="rh">
        <span class="units">
        In Millions of U.S. Dollars<br/>
        (except for per share items)<br/>
        </span>
    </th>
    <th class="data">
        2012<br/>
        2012-09-30<br/>
        <span class="period">
        </span>
      </th>
      <th class="data">
        2012<br/>
        2012-06-30<br/>
        <span class="period">
        </span>
      </th>
      <th class="data">
        2012<br/>
        2012-03-31<br/>
        <span class="period">
        </span>
      </th>
      <th class="data">
        2011<br/>
        2011-12-31<br/>
        <span class="period">
        Reclassified<br/>
        2012-06-30<br/>
        </span>
      </th>
      <th class="data">
        2011<br/>
        2011-09-30<br/>
        <span class="period">
        </span>
      </th>
      </tr>

  <tr class="both stripe ">
        <td class="rh">Cash</td>
        <td class="data plus">6,224.0</td>
          <td class="data plus">7,463.0</td>
          <td class="data plus">11,239.0</td>
          <td class="data plus">4,712.0</td>
          <td class="data plus">4,209.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Cash & Equivalents</td>
        <td class="data plus">10,036.0</td>
          <td class="data plus">7,974.0</td>
          <td class="data plus">11,869.0</td>
          <td class="data plus">5,271.0</td>
          <td class="data plus">6,421.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Short Term Investments</td>
        <td class="data plus">29,464.0</td>
          <td class="data plus">27,685.0</td>
          <td class="data plus">26,208.0</td>
          <td class="data plus">34,643.0</td>
          <td class="data plus">31,930.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Cash and Short Term Investments</td>
        <td class="data plus">45,724.0</td>
          <td class="data plus">43,122.0</td>
          <td class="data plus">49,316.0</td>
          <td class="data plus">44,626.0</td>
          <td class="data plus">42,560.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Accounts Receivable - Trade, Net</td>
        <td class="data plus">7,259.0</td>
          <td class="data plus">6,866.0</td>
          <td class="data plus">5,163.0</td>
          <td class="data plus">5,427.0</td>
          <td class="data plus">4,583.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Notes Receivable - Short Term</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Receivables - Other</td>
        <td class="data plus">550.0</td>
          <td class="data plus">475.0</td>
          <td class="data plus">550.0</td>
          <td class="data plus">745.0</td>
          <td class="data plus">1,278.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Total Receivables, Net</td>
        <td class="data plus">7,809.0</td>
          <td class="data plus">7,341.0</td>
          <td class="data plus">5,713.0</td>
          <td class="data plus">6,172.0</td>
          <td class="data plus">5,861.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Total Inventory</td>
        <td class="data plus">618.0</td>
          <td class="data plus">634.0</td>
          <td class="data plus">--</td>
          <td class="data plus">35.0</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Prepaid Expenses</td>
        <td class="data plus">2,440.0</td>
          <td class="data plus">2,614.0</td>
          <td class="data plus">1,779.0</td>
          <td class="data plus">1,710.0</td>
          <td class="data plus">1,406.0</td>
          </tr>
      <tr class="sum stripe ">
        <td class="rh">Other Current Assets, Total</td>
        <td class="data plus">230.0</td>
          <td class="data plus">146.0</td>
          <td class="data plus">51.0</td>
          <td class="data plus">215.0</td>
          <td class="data plus">215.0</td>
          </tr>
      <tr class="both  total">
        <td class="rh">Total Current Assets</td>
        <td class="data plus">56,821.0</td>
          <td class="data plus">53,857.0</td>
          <td class="data plus">56,859.0</td>
          <td class="data plus">52,758.0</td>
          <td class="data plus">50,042.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Property/Plant/Equipment, Total - Gross</td>
        <td class="data plus">17,038.0</td>
          <td class="data plus">16,137.0</td>
          <td class="data plus">14,963.0</td>
          <td class="data plus">14,400.0</td>
          <td class="data plus">13,815.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Accumulated Depreciation, Total</td>
        <td class="data minus">(5,637.0)</td>
          <td class="data minus">(5,228.0)</td>
          <td class="data minus">(5,088.0)</td>
          <td class="data minus">(4,797.0)</td>
          <td class="data minus">(4,611.0)</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Property/Plant/Equipment, Total - Net</td>
        <td class="data plus">11,401.0</td>
          <td class="data plus">10,909.0</td>
          <td class="data plus">9,875.0</td>
          <td class="data plus">9,603.0</td>
          <td class="data plus">9,204.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Goodwill, Net</td>
        <td class="data plus">10,485.0</td>
          <td class="data plus">10,120.0</td>
          <td class="data plus">7,325.0</td>
          <td class="data plus">7,346.0</td>
          <td class="data plus">6,989.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Intangibles, Net</td>
        <td class="data plus">7,754.0</td>
          <td class="data plus">7,862.0</td>
          <td class="data plus">1,541.0</td>
          <td class="data plus">1,578.0</td>
          <td class="data plus">1,474.0</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Long Term Investments</td>
        <td class="data plus">1,063.0</td>
          <td class="data plus">1,040.0</td>
          <td class="data plus">880.0</td>
          <td class="data plus">790.0</td>
          <td class="data plus">891.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Note Receivable - Long Term</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Other Long Term Assets, Total</td>
        <td class="data plus">2,206.0</td>
          <td class="data plus">2,263.0</td>
          <td class="data plus">664.0</td>
          <td class="data plus">499.0</td>
          <td class="data plus">488.0</td>
          </tr>
      <tr class="sum stripe ">
        <td class="rh">Other Assets, Total</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  total">
        <td class="rh">Total Assets</td>
        <td class="data plus">89,730.0</td>
          <td class="data plus">86,051.0</td>
          <td class="data plus">77,144.0</td>
          <td class="data plus">72,574.0</td>
          <td class="data plus">69,088.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Accounts Payable</td>
        <td class="data plus">2,233.0</td>
          <td class="data plus">2,419.0</td>
          <td class="data plus">760.0</td>
          <td class="data plus">588.0</td>
          <td class="data plus">563.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Payable/Accrued</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Accrued Expenses</td>
        <td class="data plus">6,347.0</td>
          <td class="data plus">5,551.0</td>
          <td class="data plus">3,429.0</td>
          <td class="data plus">4,356.0</td>
          <td class="data plus">3,563.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Notes Payable/Short Term Debt</td>
        <td class="data plus">3,218.0</td>
          <td class="data plus">3,218.0</td>
          <td class="data plus">2,468.0</td>
          <td class="data plus">1,218.0</td>
          <td class="data plus">1,218.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Current Port. of  LT Debt/Capital Leases</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Other Current liabilities, Total</td>
        <td class="data plus">2,636.0</td>
          <td class="data plus">2,840.0</td>
          <td class="data plus">3,085.0</td>
          <td class="data plus">2,751.0</td>
          <td class="data plus">3,544.0</td>
          </tr>
      <tr class="both stripe total">
        <td class="rh">Total Current Liabilities</td>
        <td class="data plus">14,434.0</td>
          <td class="data plus">14,028.0</td>
          <td class="data plus">9,742.0</td>
          <td class="data plus">8,913.0</td>
          <td class="data plus">8,888.0</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Long Term Debt</td>
        <td class="data plus">2,988.0</td>
          <td class="data plus">2,987.0</td>
          <td class="data plus">2,987.0</td>
          <td class="data plus">2,986.0</td>
          <td class="data plus">2,986.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Capital Lease Obligations</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Total Long Term Debt</td>
        <td class="data plus">2,988.0</td>
          <td class="data plus">2,987.0</td>
          <td class="data plus">2,987.0</td>
          <td class="data plus">2,986.0</td>
          <td class="data plus">2,986.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Total Debt</td>
        <td class="data plus">6,206.0</td>
          <td class="data plus">6,205.0</td>
          <td class="data plus">5,455.0</td>
          <td class="data plus">4,204.0</td>
          <td class="data plus">4,204.0</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Deferred Income Tax</td>
        <td class="data plus">1,461.0</td>
          <td class="data plus">1,509.0</td>
          <td class="data plus">384.0</td>
          <td class="data plus">287.0</td>
          <td class="data plus">263.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Minority Interest</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Other Liabilities, Total</td>
        <td class="data plus">2,819.0</td>
          <td class="data plus">2,806.0</td>
          <td class="data plus">2,319.0</td>
          <td class="data plus">2,243.0</td>
          <td class="data plus">2,121.0</td>
          </tr>
      <tr class="both stripe total">
        <td class="rh">Total Liabilities</td>
        <td class="data plus">21,702.0</td>
          <td class="data plus">21,330.0</td>
          <td class="data plus">15,432.0</td>
          <td class="data plus">14,429.0</td>
          <td class="data plus">14,258.0</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Redeemable Preferred Stock, Total</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="sum stripe ">
        <td class="rh">Preferred Stock - Non Redeemable, Net</td>
        <td class="data plus">0.0</td>
          <td class="data plus">0.0</td>
          <td class="data plus">0.0</td>
          <td class="data plus">0.0</td>
          <td class="data plus">0.0</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Common Stock, Total</td>
        <td class="data plus">22,204.0</td>
          <td class="data plus">21,357.0</td>
          <td class="data plus">20,795.0</td>
          <td class="data plus">20,264.0</td>
          <td class="data plus">19,697.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Additional Paid-In Capital</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Retained Earnings (Accumulated Deficit)</td>
        <td class="data plus">45,456.0</td>
          <td class="data plus">43,280.0</td>
          <td class="data plus">40,495.0</td>
          <td class="data plus">37,605.0</td>
          <td class="data plus">34,901.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Treasury Stock - Common</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  ">
        <td class="rh">ESOP Debt Guarantee</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Unrealized Gain (Loss)</td>
        <td class="data plus">566.0</td>
          <td class="data plus">389.0</td>
          <td class="data plus">416.0</td>
          <td class="data plus">327.0</td>
          <td class="data plus">99.0</td>
          </tr>
      <tr class="sum  ">
        <td class="rh">Other Equity, Total</td>
        <td class="data minus">(198.0)</td>
          <td class="data minus">(305.0)</td>
          <td class="data plus">6.0</td>
          <td class="data minus">(51.0)</td>
          <td class="data plus">133.0</td>
          </tr>
      <tr class="both stripe total">
        <td class="rh">Total Equity</td>
        <td class="data plus">68,028.0</td>
          <td class="data plus">64,721.0</td>
          <td class="data plus">61,712.0</td>
          <td class="data plus">58,145.0</td>
          <td class="data plus">54,830.0</td>
          </tr>
      <tr class="both  total">
        <td class="rh">Total Liabilities & Shareholders' Equity</td>
        <td class="data plus">89,730.0</td>
          <td class="data plus">86,051.0</td>
          <td class="data plus">77,144.0</td>
          <td class="data plus">72,574.0</td>
          <td class="data plus">69,088.0</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Shares Outs - Common Stock Primary Issue</td>
        <td class="data plus">264.52</td>
          <td class="data plus">261.58</td>
          <td class="data plus">259.50</td>
          <td class="data plus">257.55</td>
          <td class="data plus">255.70</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Shares Outstanding - Common Issue 2</td>
        <td class="data plus">64.04</td>
          <td class="data plus">65.36</td>
          <td class="data plus">66.40</td>
          <td class="data plus">67.34</td>
          <td class="data plus">68.05</td>
          </tr>
      <tr class="both stripe ">
        <td class="rh">Shares Outstanding - Common Issue 3</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both  ">
        <td class="rh">Shares Outstanding - Common Issue 4</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      <tr class="both stripe total">
        <td class="rh">Total Common Shares Outstanding</td>
        <td class="data plus">328.55</td>
          <td class="data plus">326.94</td>
          <td class="data plus">325.91</td>
          <td class="data plus">324.89</td>
          <td class="data plus">323.76</td>
          </tr>
      <tr class="both  total">
        <td class="rh">Total Preferred Shares Outstanding</td>
        <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          <td class="data plus">--</td>
          </tr>
      </table>

</div>
    </div>
    </div>

Cuando trato de usar la variable TotalCurrentAssets para extraer la segunda columna de la fila Total de Activos Actuales (el número debería ser 53,857.0). Recibo "NullReferenceException no fue manejada por el código de usuario. La referencia del objeto no está establecida en una instancia del objeto".

¿Significa esto que la variable TotalCurrentAssets no devuelve nada? Estoy asumiendo que mi error está en mi última línea de código.

INFORMACIÓN ADICIONAL

No sé si esto afecta mi problema o no, pero ejecuto este código antes del código de mi publicación original:

Dim wreqBeta As HttpWebRequest = WebRequest.Create("http://www.reuters.com/finance/stocks/overview?symbol=" & tickerValue)
        wreqBeta.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"
        wreqBeta.Method = "get"
        Dim proxBeta As IWebProxy = wreqBeta.Proxy
        proxBeta.Credentials = CredentialCache.DefaultCredentials
        Dim documentBeta As New HtmlAgilityPack.HtmlDocument
        Dim webBeta As New HtmlAgilityPack.HtmlWeb
        webBeta.UseCookies = True
        webBeta.PreRequest = New HtmlAgilityPack.HtmlWeb.PreRequestHandler(AddressOf onPreReq)
        wreqBeta.CookieContainer = cookies
        Dim resBeta As HttpWebResponse = wreqBeta.GetResponse()
        documentBeta.Load(resBeta.GetResponseStream, True)
        Dim beta = documentBeta.DocumentNode.SelectSingleNode("//div[@id='overallRatios']//table[@class='dataTable']//tr[1]//td[2]")

¿Debo cerrar algo de este código antes de comenzar a analizar la nueva página web?

Respuesta aceptada

La coincidencia de nombres para los atributos distingue mayúsculas de minúsculas. Su HTML contiene *f* inancials , su código espera *F* inancials .

Puede usar //table[upper-case(@class)=upper-case('dataTable financials')] para evitar este tipo de problemas cuando la sensibilidad a los casos no es importante. o puede utilizar la función de matches XPath 2.0.

Además de eso, asegúrese de que la página web a la que está accediendo realmente devuelva los datos que está esperando. En mi prueba local, la página que se devuelve no contiene una tabla con datos similares a su muestra.

Ponga un reloj en documentBalQtr.DocumentNode.OuterHtml para verificar que su página realmente coincida con lo que está esperando.



Related

Licencia bajo: CC-BY-SA with attribution
No afiliado con Stack Overflow
Licencia bajo: CC-BY-SA with attribution
No afiliado con Stack Overflow