フォーム入力値をWebページからURLRequestに読み込みますか?
-
10-07-2019 - |
質問
以下の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>
解決 2
elementParser を使用しました。ありがとう!
他のヒント
HTMLも有効なXMLであることがわかっている場合は、NSXMLParser(または他のXML解析コード)全体を実行し、フォーム入力である要素(<input>
など)を検出するたびに何らかのアクションを実行できます)。
それ以外の場合は、独自の文字列解析関数を作成する方がよい場合があります。取得するタグのインスタンスを探し、<!> lt;の間にあるすべてのテキストを取得します。および<!> gt;文字を入力し、スペースで分割し、入力フィールドの名前を見つけてNSURLConnectionに入力できるようにします。
所属していません StackOverflow