【发布时间】:2013-07-09 13:48:02
【问题描述】:
我编写了一个应用程序,它下载然后从 html 文件中抓取数据。该应用程序几个月来一直运行良好,但最近几天就停止了。
这里是代码...
NSString* urlString = [@"http://easytide.ukho.gov.uk/EASYTIDE/EasyTide/ShowPrediction.aspx?PortID=" stringByAppendingString:portCode];
urlString = [urlString stringByAppendingString:@"&PredictionLength=7"];
NSURL* easyTidesUrl = [NSURL URLWithString:urlString];
NSData* easyTidesHtmlData = [NSData dataWithContentsOfURL:easyTidesUrl];
当我检查 NSURL 对象时,url 没有正确设置(字符串有错误)并且 NSURL 对象显示为 .我知道过去曾有人问过类似的问题(我已经尝试过解决方案,但在这种情况下它们不起作用),但奇怪的是,该应用程序运行良好,但现在没有做任何事情就被破坏了!
这里还有一些代码...基本上停止工作的部分是函数的第一部分...
+(void)getTides:(NSMutableArray *)tidalDateArray withPortCode:(NSString*)portCode
{
NSString *parameter = [portCode stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"http://easytide.ukho.gov.uk/EASYTIDE/EasyTide/ShowPrediction.aspx?PortID=%@&PredictionLength=7", parameter];
NSURL *easyTidesUrl = [NSURL URLWithString:urlString];
NSData *easyTidesHtmlData = [NSData dataWithContentsOfURL:easyTidesUrl];
TFHpple* tidesParser = [TFHpple hppleWithHTMLData:easyTidesHtmlData];
NSString* easyTidesXPathQueryString = @"//div[@class='HWLWPanel']/table/tr/th[@class='HWLWTableHeaderCell']";
NSArray* tideDateNodes = [tidesParser searchWithXPathQuery:easyTidesXPathQueryString];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
【问题讨论】:
-
你得到 NSURL *easyTidesUrl nil 吗?
-
不,NSURL 对象有一个内存地址等,所以我假设它已初始化......问题似乎出在 nsurl.urlString
-
我尝试了上面的地址并被重定向到一个错误页面...如果您没有修改应用程序并且它无缘无故地中断,那么问题可能出在其他地方。我怀疑网站或主机服务器可能会发生变化。