문제

지금까지 다음 코드가 있습니다.

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]")

그리고 HTML은 다음과 같습니다.

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

TotalCurrentAssets 변수를 사용하여 총 현재 자산 행에서 두 번째 열을 가져 오려고 시도하면 (번호는 53,857.0이어야 함) "NullReferenceException이 사용자 코드에 의해 처리되지 않았습니다. 객체 참조가 객체의 인스턴스로 설정되지 않았습니다."

이것은 변수 TotalCurrentAssets가 아무것도 반환하지 않는다는 것을 의미합니까? 내 오류가 내 마지막 코드 줄에 있다고 가정합니다.

추가 정보

나는 내 문제에 영향을 미치는지 아닌지는 모르겠지만 원래 코드의 코드보다 먼저이 코드를 실행합니다.

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]")

새 웹 페이지를 파싱하기 전에이 코드의 내용을 닫아야합니까?

수락 된 답변

속성의 이름 일치는 대소 문자를 구분합니다. HTML에 *f* inancials 가 포함되어 있으므로 코드에서 *F* inancials 예상됩니다.

//table[upper-case(@class)=upper-case('dataTable financials')] 소문자 구분이 중요하지 않은 경우 이러한 유형의 문제를 방지하려면 //table[upper-case(@class)=upper-case('dataTable financials')] 를 사용할 수 있습니다. 또는 XPath 2.0 matches 함수를 사용할 수 있습니다.

그 위에 실제로 액세스하는 웹 페이지가 예상하는 데이터를 반환하는지 확인하십시오. 내 로컬 테스트에서 반환되는 페이지에 샘플과 비슷한 데이터가있는 테이블이 없습니다.

documentBalQtr.DocumentNode.OuterHtml 에 시계를 배치하여 페이지가 예상 한 것과 실제로 일치하는지 확인하십시오.




아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.
아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.