0

我将如何提取下面 html 源的表单值并将它们添加到 NSURLConnection?

<tr>
                            <th><label for="username"><span class="accesskey">N</span>etID:</label></th>
                            <td><input id="username" name="username" class="required" tabindex="1" accesskey="n" type="text" value="" size="32" autocomplete="false"/></td>
                        </tr><tr>
                            <th><label for="password"><span class="accesskey">P</span>assword:</label></th>
                            <td><input id="password" name="password" class="required" tabindex="2" accesskey="p" type="password" value="" size="32"/></td>
                        </tr><tr>
                            <th><label for="authenticationType"><span class="accesskey">A</span>uthentication Type:</label></th>
                            <td>
                               <select id="authenticationType" name="authenticationType">
                                  <option value="Kerberos">Default</option>
                                  <option value="SafeWord">SafeWord</option>
                               </select>
                            </td>
                        </tr><tr>
                            <th></th>
                            <td>
                                <input type="checkbox" id="warn" name="warn" value="true" tabindex="3" />
                                <label for="warn" class="other" accesskey="w"><span class="accesskey">W</span>arn me before logging me into other sites.</label>
                            </td>
                        </tr><tr>
                            <th></th>
                            <td>
                                <input type="hidden" name="_currentStateId" value="" />
                                <input type="hidden" name="_eventId" value="submit" />
                                <input type="submit" accesskey="l" value="LOGIN" tabindex="4" />
                            </td>
                        </tr>
4

2 回答 2

0

如果您知道 HTML 也是有效的 XML,您可以通过 NSXMLParser(或其他 XML 解析代码)运行整个内容,并在检测到作为表单输入的元素(例如<input>)时执行一些操作。

否则,您最好只编写自己的字符串解析函数 - 查找要抓取的标签的任何实例,拉出 < 和 > 字符之间的所有文本,用空格分隔,然后找到输入字段的名称,以便您可以将其放入 NSURLConnection。

于 2009-08-03T03:18:03.263 回答
0

我使用了 elementParser。谢谢!

于 2009-08-03T06:12:40.783 回答