C++,如何在html代码中获得特定的字符串
C++ , how do i get a particular string in a html code
我正在尝试解析这个XMLYahoo提要。
我喜欢如何将每个记录放入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;
}
相关文章:
- 编译包含字符串的代码时遇到问题
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 我应该如何修改此代码以使用给定字符串中的字母打印菱形图案
- 我无法在 qt 的C++代码中定义字符串
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 有人可以解释一下这段代码如何能够反转字符串
- 如何在 c++ 非托管代码中反序列化 byte[] 的 json 字符串?
- 我遇到了这个代码片段,不明白. 它递归检查 C++ 字符串中是否存在大写字符
- 如何用符合C++核心准则的代码替换C风格的字符串解析
- C++/CLI访问字符串::来自非CLI代码的格式
- MSVC UTF8字符串编码使用了不正确的代码点
- C++指向对象的指针堆数组中,如何将字符串传递给特定对象?有一些代码请看一下:
- 将浮点数转换为字符串时如何加快此代码的速度?
- C++代码,用于在用户插入的字符串的每个元音之后插入一对字符
- 如何获取包含 NULL 字符的外壳代码字符串的长度
- 字符串代码不起作用
- C++字符串代码点和代码单元的任何良好解决方案
- 输入验证,需要数字,而不是字符串.代码导致无限循环
- 使用引用传递方法的反向字符串代码不起作用
- 这个反向字符串代码正确吗