[英]C++ , how do i get a particular string in a html code
您可能要查看給定的頁面是否以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.