簡體   English   中英

C ++,如何在html代碼中獲取特定的字符串

[英]C++ , how do i get a particular string in a html code

我正在嘗試解析此XML Yahoo feed

我喜歡如何將每條記錄放入C ++的數組中,例如創建結構

然后獲取這些變量並記錄結構中的每個元素。

首先,我如何獲得價值

謝謝

您可能要查看給定的頁面是否以JSON格式提供輸出。 然后,您可以簡單地請求該值,而不用搞亂HTML。 雅虎! 財務站點甚至可以提供一個API,您可以使用它輕松地請求該值。

如果您想弄亂html代碼:

#include <iostream>
#include <fstream>
int main() {
  std::ifstream ifile("in.html");
  std::string line;
  std::string ndl("<span id=\"yfs_l10_sgdmyr=x\">");
  while(ifile.good()){ 
    getline(ifile, line);
    if (line.size()) {
      size_t spos, epos;
      if ((spos = line.find(ndl)) != std::string::npos) {
        spos += ndl.size();
        if ((epos = line.find(std::string("</span>"), spos)) != std::string::npos) {
          std::cout << line.substr(spos, epos-spos) << std::endl;
        }   
      }   
    }   
  }   
  return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM