URL www.drugs.com/imprints.phpをスクラップするiPhoneアプリを書いています。 それは四つのパラメータ(名前、インプリント、色、形)のいずれかを取り、のように見えるURLパラメータにそれをプラグ:ここiOSのスクリーンスクラップを含むObjective-C&Cocoa Touchの問題
http://www.drugs.com/imprints.php?action=search&imprint=%@&color=%@&shape=%@&drugname=%@
は私がスクレイピングを行うために書いたコードのセグメントであります:
NSString *name = [[NSString alloc] initWithFormat:@"%@", [ask text]];
NSString *imprint = [[NSString alloc] initWithFormat:@"%@", [imp text]];
NSString *color = [[NSString alloc] initWithFormat:@"%@", [col text]];
NSString *shape = [[NSString alloc] initWithFormat:@"%@", [sha text]];
NSString *address = @"http://www.drugs.com/imprints.php?action=search&drugname=";
NSString *request = [NSString stringWithFormat:@"http://www.drugs.com/imprints.php?action=search&imprint=%@&color=%@&shape=%@&drugname=%@",imprint,color,shape,name];
NSString *escapedUrl = [request
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *URL = [NSURL URLWithString:escapedUrl];
NSString *txtToScrape = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];
NSString *drugName= [[[[txtToScrape componentsSeparatedByString:@"q="] objectAtIndex:1] componentsSeparatedByString:@">"] objectAtIndex:0];
NSString *drugImage = [[[[txtToScrape componentsSeparatedByString:@"images/pills/mmx/"] objectAtIndex:1] componentsSeparatedByString:@");"] objectAtIndex:0];
NSString *drugDesc = [[[[txtToScrape componentsSeparatedByString:@"/imprints/"] objectAtIndex:1] componentsSeparatedByString:@".html"] objectAtIndex:0];
基本的にコードは、薬剤情報をビューに戻して文字列にします。私はcomponentsSeparatedByStringを使用していて、コード内のさまざまな「キー」タグと単語を探していて、HTMLのアーティファクトに基づいてそれらを返す/解析しています。
今、私の質問は、これを行うには良い方法がありますか?私はiOSプログラミングを初めて学び、より効率的なものを見落としているように感じます。また、AppStoreでこれを配布する場合は、サードパーティのWebサイトを掻き集めているので正当だろうか?私はそれを販売する計画はありませんが、無料でそれを与える。最後に、UIにexitボタンがありますが、iOS Appsでexitボタンを使用するのはどうですか?それのためにAppleは赤旗を立てるだろうか? (終了ボタンは終了します(0);)。
申し訳ありませんが、私はココアとiOSの開発を初めて行っています。
それは本当にリーを知って良いです。ありがとう。 – ApolloSoftware