我正在使用hpple尝试从ThePirateBay获取torrent描述。目前,我正在使用此代码:
NSString *path = @"//div[@id='content']/div[@id='main-content']/div/div[@id='detailsouterframe']/div[@id='detailsframe']/div[@id='details']/div[@class='nfo']/pre/node()";
NSArray *nodes = [parser searchWithXPathQuery:path];
for (TFHppleElement * element in nodes) {
NSString *postid = [element content];
if (postid) {
[texts appendString:postid];
}
}
这只返回纯文本,而不是屏幕截图的任何URL。反正有没有获得所有链接和其他标签,而不仅仅是纯文本? 盗版者就是这样的:
<pre>
<a href="http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg" rel="nofollow">
http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg</a>
More texts about the file
</pre>
答案 0 :(得分:1)
这是一项轻松的工作,你几乎可以正确地完成它!
你想要的是a
- 标签的内容(或属性),所以你需要告诉解析器你想要它。
只需将XPath
更改为
@"//div[@id='content']/div[@id='main-content']/div/div[@id='detailsouterframe']/div[@id='detailsframe']/div[@id='details']/div[@class='nfo']/pre/a"
(您错过了最后的a
而您不需要node()
)
<强>输出:强>
http://www.imdb.com/title/tt1904996/
http://leetleech.org/images/65823608764828593230.png
http://leetleech.org/images/44748070481477652927.png
http://leetleech.org/images/42024611449329122742.png
如果您只想要屏幕截图网址,则可以执行类似
的操作NSMutableArray *screenshotURLs = [[NSMutableArray alloc] initWithCapacity:0];
for (int i = 1; i < nodes.count; i++) {
[screenshotURLs addObject:nodes[i]];
}