0

I have written an app that downloads and then scrapes data from an html file. The app has been working fine for months, but the last couple of days it has stopped.

Here is the code...

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];

When I examine the NSURL object, the url has not set properly (there is an error with the string) and the NSURL object is shown as . I know similar questions have been asked in the past (i have tried the solutions and they don't work in this instance), but it seems bizarre that the app was working fine and is now broken without doing anything to it!


Here is some more code... basically the part that has stopped working is the first part of the function...

+(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];
4

3 回答 3

1

Easytide 似乎已关闭,因此可能不是 API 问题!

于 2013-07-09T15:40:12.770 回答
0

变量中可能存在一些非法章程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];
于 2013-07-09T13:56:05.463 回答
0

问题看起来毕竟是一个非常简单的问题......网址本身是错误的 - 无论是他们改变了它还是它是否在我不知道的代码中被改变了......谢谢你的所有帮助和代码改进...

于 2013-07-10T15:48:01.257 回答