2

あなたの助けが必要です。HTML を解析しようとするのはこれが初めてで、いくつかの問題が発生しています。HTML 解析に関するRays チュートリアルに従いました。彼はhppleを使用しています。私が解析したいファイルは、彼のものよりもはるかに複雑です。以下のコードを使用して、いくつかの変数を抽出したいと思います。

<div id="status">
<div id="loading" style="display:none">Error:<br />Connection to demo board was lost.</div>
<div id="display">
    <span style="float:right;font-size:9px;font-weight:normal;padding-top:8px;text-indent:0px">(click to toggle)</span>
    <p>LEDs:<br /><span class="leds">
    <!-- <a id="led7" onclick="newAJAXCommand('leds.cgi?led=7');">&bull;</a>
    <a id="led6" onclick="newAJAXCommand('leds.cgi?led=6');">&bull;</a>
    <a id="led5" onclick="newAJAXCommand('leds.cgi?led=5');">&bull;</a>
    <a id="led4" onclick="newAJAXCommand('leds.cgi?led=4');">&bull;</a>
    <a id="led3" onclick="newAJAXCommand('leds.cgi?led=3');">&bull;</a>
    <a id="led2" onclick="newAJAXCommand('leds.cgi?led=2');">&bull;</a> -->
    <a id="led1" onclick="newAJAXCommand('leds.cgi?led=1');">&bull;</a>
    <!-- <a id="led0">&bull;</a> -->
    </span></p>
    <p>Buttons:<br />
    <!-- <span id="btn3">?</span> &nbsp; 
    <span id="btn2">?</span> &nbsp; 
    <span id="btn1">?</span> &nbsp;  -->
    <span id="btn0">?</span></p>
    <p>Potentiometer: <span id="pot0" style="font-weight:normal">?</span></p> 
    <p>Temperature: <span id="temp0" style="font-weight:normal">?</span></p> 
</div>

これまでのところ、LED、ボタン、ポテンショメータ、および温度を取得できます。それらの値を取得できません。(これらの特定の 4 つのフィールドの値)。

以下のコードを使用しています。

- (void)loadTutorials {
// 1
NSURL *tutorialsUrl = [NSURL URLWithString:@"http://192.168.0.112/"]; 
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];

// 2
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];

// 3
NSString *tutorialsXpathQueryString = @"//div[@id='display']/p"; 
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];

// 4
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
    // 5
    Tutorial *tutorial = [[Tutorial alloc] init];
    [newTutorials addObject:tutorial];
    NSLog(@"Object=%@",element);
    // 6
    tutorial.title = [[element firstChild] content]; 

    // 7
    tutorial.url = [element objectForKey:@"???"]; //??? 
}

// 8
_objects = newTutorials;
[self.tableView reloadData];

}

問題はobjectForKeyにあると思われます:しかし、よくわかりません。想像できるあらゆる種類のキーをテストしました。どんな助けでも大歓迎です。

4

0 に答える 0