PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Formular namen automatisch ermitteln


Martuzki
25.09.2009, 18:08:42
Hallo zusammen!

Ich Tippe bei einer Tipprunde bei Kicktipp.de mit. Da ich aber manchmal keine zeit habe die ergebnisse einzutragen wollte ich mir ein PHP-Script machen was alles automatisch macht.
Das Login und das senden der ergebnisse mache ich mit cURL. Das klappt auch schon ganz gut nur ich muss von Spieltag zu Spieltag die POST-Paramenter selber ändern da sie auch die Namen der Inputfelder von spieltag zu spieltag ändern.

Hier ist mal mein PHP Script:

Script ist unten

Und hier mal das Tipp-Formular:

Code ist unten

Der "name" aller Input-Felder ändert sich von Woche zu Woche. Das Script soll dan automatisch die namen der Input-Felder erkennen.

Hoffe ihr könnt mir herlfen

lg Ich

Martuzki
25.09.2009, 18:12:47
Mein Script-Code:

<?php

curl_login1("http://www.kicktipp.de/Runde/loginaction;jsessionid=77CFC11CC5FCA1423358946E18B96515.krabbe", "j_username=Name&j_password=PW&_charset_=UTF-8&submitbutton=Anmelden", "", "off");

//echo curl_grab_page1("http://www.kicktipp.de/juli98/tippabgabe", "", "off"); //Wenn keine 2. funktion vorhanden ist

function curl_login1($url,$data,$proxy,$proxystatus){
$fp = fopen("cookie.txt", "w");
fclose($fp);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($login, CURLOPT_TIMEOUT, 40);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($login, CURLOPT_PROXY, $proxy);
}
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, TRUE);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start(); // prevent any output
return curl_exec ($login); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($login);
unset($login);
}

function curl_grab_page1($site,$proxy,$proxystatus){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start(); // prevent any output
return curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
}

srand ((double) microtime() * 10000);
$heim1 = rand(0,4);
$heim2 = rand(0,4);
$heim3 = rand(0,4);
$heim4 = rand(0,4);
$heim5 = rand(0,4);
$heim6 = rand(0,4);
$heim7 = rand(0,4);
$heim8 = rand(0,4);
$heim9 = rand(0,4);
$aus1 = rand(0,4);
$aus2 = rand(0,4);
$aus3 = rand(0,4);
$aus4 = rand(0,4);
$aus5 = rand(0,4);
$aus6 = rand(0,4);
$aus7 = rand(0,4);
$aus8 = rand(0,4);
$aus9 = rand(0,4);

curl_tipp("http://www.kicktipp.de/Runde/tippabgabe", "mitgliedId=257812&tippspieltagIndex=7&spieltippForms%5B39755552%5D.tippspielId=39755552&spieltippForms%5B39755552%5D.mitgliedId=257812&spieltippForms%5B39755552%5D.tippAbgegeben=true&spieltippForms%5B39755552%5D.heimTipp=$heim1&spieltippForms%5B39755552%5D.gastTipp=$aus1&spieltippForms%5B39755550%5D.tippspielId=39755550&spieltippForms%5B39755550%5D.mitgliedId=257812&spieltippForms%5B39755550%5D.tippAbgegeben=true&spieltippForms%5B39755550%5D.heimTipp=$heim2&spieltippForms%5B39755550%5D.gastTipp=$aus2&spieltippForms%5B39755546%5D.tippspielId=39755546&spieltippForms%5B39755546%5D.mitgliedId=257812&spieltippForms%5B39755546%5D.tippAbgegeben=true&spieltippForms%5B39755546%5D.heimTipp=$heim3&spieltippForms%5B39755546%5D.gastTipp=$aus3&spieltippForms%5B39755553%5D.tippspielId=39755553&spieltippForms%5B39755553%5D.mitgliedId=257812&spieltippForms%5B39755553%5D.tippAbgegeben=true&spieltippForms%5B39755553%5D.heimTipp=$heim4&spieltippForms%5B39755553%5D.gastTipp=$aus4&spieltippForms%5B39755547%5D.tippspielId=39755547&spieltippForms%5B39755547%5D.mitgliedId=257812&spieltippForms%5B39755547%5D.tippAbgegeben=true&spieltippForms%5B39755547%5D.heimTipp=$heim5&spieltippForms%5B39755547%5D.gastTipp=$aus5&spieltippForms%5B39755549%5D.tippspielId=39755549&spieltippForms%5B39755549%5D.mitgliedId=257812&spieltippForms%5B39755549%5D.tippAbgegeben=true&spieltippForms%5B39755549%5D.heimTipp=$heim6&spieltippForms%5B39755549%5D.gastTipp=$aus6&spieltippForms%5B39755545%5D.tippspielId=39755545&spieltippForms%5B39755545%5D.mitgliedId=257812&spieltippForms%5B39755545%5D.tippAbgegeben=true&spieltippForms%5B39755545%5D.heimTipp=$heim7&spieltippForms%5B39755545%5D.gastTipp=$aus7&spieltippForms%5B39755548%5D.tippspielId=39755548&spieltippForms%5B39755548%5D.mitgliedId=257812&spieltippForms%5B39755548%5D.tippAbgegeben=true&spieltippForms%5B39755548%5D.heimTipp=$heim8&spieltippForms%5B39755548%5D.gastTipp=$aus8&spieltippForms%5B39755551%5D.tippspielId=39755551&spieltippForms%5B39755551%5D.mitgliedId=257812&spieltippForms%5B39755551%5D.tippAbgegeben=true&spieltippForms%5B39755551%5D.heimTipp=$heim9&spieltippForms%5B39755551%5D.gastTipp=$aus9&submitbutton=Tipps+speichern&_charset_=UTF-8", "", "off");


$abgabe = curl_grab_page2("http://www.kicktipp.de/Runde/tippabgabe", "", "off");

echo ($abgabe);

function curl_tipp($url,$data,$proxy,$proxystatus){
$fp = fopen("cookie.txt", "w");
fclose($fp);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($login, CURLOPT_TIMEOUT, 40);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($login, CURLOPT_PROXY, $proxy);
}
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, TRUE);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start(); // prevent any output
return curl_exec ($login); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($login);
unset($login);
}

function curl_grab_page2($site,$proxy,$proxystatus){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start(); // prevent any output
return curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
}

?>

Martuzki
25.09.2009, 18:13:45
HTML Form:

<form id="tippabgabeForm" action="tippabgabe" method="post" accept-charset="UTF-8">

<input id="mitgliedIdHidden" name="mitgliedId" type="hidden" value="257812"/>
<input id="tippspieltagIndexHidden" name="tippspieltagIndex" type="hidden" value="7"/>

<input id="tippspielId_39755552" name="spieltippForms[39755552].tippspielId" type="hidden" value="39755552"/>
<input id="mitgliedId_39755552" name="spieltippForms[39755552].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755552.tippAbgegeben" name="spieltippForms[39755552].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755552.heimTipp" name="spieltippForms[39755552].heimTipp" class="selectOnLoad" type="text" value="1" size="3" maxlength="3"/>
<input id="spieltippForms_39755552.gastTipp" name="spieltippForms[39755552].gastTipp" type="text" value="2" size="3" maxlength="3"/>

<input id="tippspielId_39755550" name="spieltippForms[39755550].tippspielId" type="hidden" value="39755550"/>
<input id="mitgliedId_39755550" name="spieltippForms[39755550].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755550.tippAbgegeben" name="spieltippForms[39755550].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755550.heimTipp" name="spieltippForms[39755550].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755550.gastTipp" name="spieltippForms[39755550].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755546" name="spieltippForms[39755546].tippspielId" type="hidden" value="39755546"/>
<input id="mitgliedId_39755546" name="spieltippForms[39755546].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755546.tippAbgegeben" name="spieltippForms[39755546].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755546.heimTipp" name="spieltippForms[39755546].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755546.gastTipp" name="spieltippForms[39755546].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755553" name="spieltippForms[39755553].tippspielId" type="hidden" value="39755553"/>
<input id="mitgliedId_39755553" name="spieltippForms[39755553].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755553.tippAbgegeben" name="spieltippForms[39755553].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755553.heimTipp" name="spieltippForms[39755553].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755553.gastTipp" name="spieltippForms[39755553].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755547" name="spieltippForms[39755547].tippspielId" type="hidden" value="39755547"/>
<input id="mitgliedId_39755547" name="spieltippForms[39755547].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755547.tippAbgegeben" name="spieltippForms[39755547].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755547.heimTipp" name="spieltippForms[39755547].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755547.gastTipp" name="spieltippForms[39755547].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755549" name="spieltippForms[39755549].tippspielId" type="hidden" value="39755549"/>
<input id="mitgliedId_39755549" name="spieltippForms[39755549].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755549.tippAbgegeben" name="spieltippForms[39755549].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755549.heimTipp" name="spieltippForms[39755549].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755549.gastTipp" name="spieltippForms[39755549].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755545" name="spieltippForms[39755545].tippspielId" type="hidden" value="39755545"/>
<input id="mitgliedId_39755545" name="spieltippForms[39755545].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755545.tippAbgegeben" name="spieltippForms[39755545].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755545.heimTipp" name="spieltippForms[39755545].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755545.gastTipp" name="spieltippForms[39755545].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755548" name="spieltippForms[39755548].tippspielId" type="hidden" value="39755548"/>
<input id="mitgliedId_39755548" name="spieltippForms[39755548].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755548.tippAbgegeben" name="spieltippForms[39755548].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755548.heimTipp" name="spieltippForms[39755548].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755548.gastTipp" name="spieltippForms[39755548].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input id="tippspielId_39755551" name="spieltippForms[39755551].tippspielId" type="hidden" value="39755551"/>
<input id="mitgliedId_39755551" name="spieltippForms[39755551].mitgliedId" type="hidden" value="257812"/>

<input value="true" id="spieltippForms_39755551.tippAbgegeben" name="spieltippForms[39755551].tippAbgegeben" type="hidden"/>
<input id="spieltippForms_39755551.heimTipp" name="spieltippForms[39755551].heimTipp" class="selectOnLoad" type="text" value="" size="3" maxlength="3"/>
<input id="spieltippForms_39755551.gastTipp" name="spieltippForms[39755551].gastTipp" type="text" value="" size="3" maxlength="3"/>

<input value="Tipps speichern" name="submitbutton" type="submit"/>
<input value="" name="_charset_" type="hidden"/></form>