我發現了各種問題,最後我解決了所有問題。 首先,有必要編碼URL添加:
myURL = [myURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
然後,可以將原始(實際)TFHPPLE代碼(正好XPathQuery.m)分析階段要崩潰「導致的任何時間nodeContent和原材料是零。 因此,要解決這個崩潰我已經改變了
[resultForNode setObject:currentNodeContent forKey:@"nodeContent"];
與(注意力兩行[resultForNode ...:
if (currentNodeContent != nil)
[resultForNode setObject:currentNodeContent forKey:@"nodeContent"];
和:
[resultForNode setObject:rawContent forKey:@"raw"];
有:
if (rawContent != nil)
[resultForNode setObject:rawContent forKey:@"raw"];
我要記住的是,「導致由谷歌使用較硬的HTML代碼,我決定使用這些xpathqueries:
...
NSArray *elementsImages = [NSArray new];
NSArray *elementsPrices = [NSArray new];
elementsImages = [xpath searchWithXPathQuery:@"//html//*[@class=\"psliimg\"]"];
elementsPrices = [xpath searchWithXPathQuery:@"//html//*[@class=\"psliprice\"]"];
...
另一個不便之處當你決定,如果你要用就用for或while循環檢索各個HTML頁面,其實:
NSData *htmlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURL]];
initWithContenctsOfURL多次循環過程中不能得到正確的頁面(和調試控制檯寫了著名無法解析),所以我決定跟去改變它:
// Send a synchronous request
NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:myURL]];
NSURLResponse * response = nil;
NSError * error = nil;
NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
if (error == nil)
{
// Parse data here
}
如果你不想因爲它是由syncronous NSURLRequests maded等待這個週期」嘗試調用與父母方法(和你的ViewController不凍結等待解析器):
_dispatch_queue_t *queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(_queue, // now i call my google shopping parser cycle
^{
[self GShoppingParser];
});
通過更改類型爲NSData的變量的名稱或更改解析器變量的名稱應該改變什麼?如果你想知道結果顯然是零,沒有什麼改變。 –