V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Cwind
V2EX  ›  iDev

用Hpple解析HTML时碰到的奇怪问题

  •  
  •   Cwind · 2013-04-29 15:04:52 +08:00 · 3201 次点击
    这是一个创建于 4016 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想从 http://www.gosugamers.net/starcraft2 抓点赛事信息,具体就是Upcoming matches、Started GosuBets以及Recent results三块内容,于是用了Hpple这个库,我是这样写的:
    NSData *siteData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.gosugamers.net/starcraft2"]];

    TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:siteData];

    upcomingArray = [xpathParser searchWithXPathQuery:@"//div[@id='box_latest_gosubets_upcoming_matches']/div[@class='last_middle']"];

    startedArray = [xpathParser searchWithXPathQuery:@"//div[@id='box_latest_gosubets_started_gosubets']/div[@class='last_middle']"];

    recentArray = [xpathParser searchWithXPathQuery:@"//div[@id='box_latest_gosubets_recent_results']/div[@class='last_middle']"];

    前面两个没问题,把每一个<div class="last_middle">下的内容都找出来了,问题是recentArray, 它把10个div塞到一块去了,而且结构也乱掉了。
    我看网页源代码中这三个部分挺工整的呀,就是id不同而已,不知道为什么前面工作的好好的,第三个就出错了,捉急呀。
    2 条回复    1970-01-01 08:00:00 +08:00
    xuan_lengyue
        1
    xuan_lengyue  
       2013-04-29 19:14:19 +08:00   ❤️ 1
    hpple太烂了,为啥不用正则表达式呢。
    Cwind
        2
    Cwind  
    OP
       2013-04-29 19:25:44 +08:00
    @xuan_lengyue 因为我不会嘛,正打算开始学来着
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3992 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 05:18 · PVG 13:18 · LAX 22:18 · JFK 01:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.