gpt4 book ai didi

objective-c - 如何从 Cocoa 应用程序中网站上的表格中获取数字?

转载 作者:行者123 更新时间:2023-12-03 17:07:07 24 4
gpt4 key购买 nike

好的,这是我上一个问题的更具体的版本。

因此,网站上存在一些以 HTML 形式编码到表格中的数据。

在我的 Cocoa 应用程序中,我想下载网站的 html 代码,然后阅读 html 并从中获取数据。我希望有人能指出一些有用的类/方法来完成网站的检索并将其放入某种格式以便我可以阅读程序中的代码?

提前致谢!

最佳答案

尝试使用hpple ,它是 ObjC 的 HTML 解析器。

这是一个使用它的示例:

#import "TFHpple.h"

NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"];

// Create parser
xpathParser = [[TFHpple alloc] initWithHTMLData:data];

//Get all the cells of the 2nd row of the 3rd table
NSArray *elements = [xpathParser search:@"//table[3]/tr[2]/td"];

// Access the first cell
TFHppleElement *element = [elements objectAtIndex:0];

// Get the text within the cell tag
NSString *content = [element content];

[xpathParser release];
[data release];

关于objective-c - 如何从 Cocoa 应用程序中网站上的表格中获取数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4474864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com