Hello
Chcialem zapytac w jaki sposob zadawac pytania google za pomoca cURL-a? Napisalem taki skrypt (dziala on dla formularzy z method=POST mozna sie logowac itd.) jednak nie dziala on z google nie wiem do konca dlaczego (google uzywa GET). Co jest nie tak?
<?php
function get_website($url, $post = '', $method = '')
{
$handle = curl_init($url);
$headers = array('Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'Accept-Language: pl,en-us;q=0.7,en;q=0.3',
'Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7',
'Keep-Alive: 300',
'Connection: keep-alive');
curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008070215 (Gentoo) Firefox/3.0');
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_HEADER, 0);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_ENCODING, 'gzip');
curl_setopt($handle, CURLOPT_ENCODING, 'deflate');
curl_setopt($handle, CURLOPT_COOKIEFILE, 'Skrypty/cookies.txt');
curl_setopt($handle, CURLOPT_COOKIEJAR, 'Skrypty/cookies.txt');
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1); // follow redirection
if($method == 'POST')
{
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_HTTPGET, 0);
curl_setopt($handle, CURLOPT_POSTFIELDS, $post);
} elseif($method == 'GET') {
curl_setopt($handle, CURLOPT_POST, 0);
curl_setopt($handle, CURLOPT_HTTPGET, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, $post); <---- CHYBA TUTAJ JEST BLAD, ALE JAK TO ZROBIC INACZEJ?
}
$output = curl_exec($handle);
if(curl_errno($handle))
{
echo('Error:'.curl_errno
($handle).'-> '.curl_error
($handle)); } else {
curl_close($handle);
}
}
$method=GET;
$post=array(\"q\"=>\"onet\", \"btnG\"=>\"Szukaj w Google\"); get_website(\"google.pl\", $post, $method);
?>
I jeszcze jedno pytanie, co zrobic w przypadku gdzie zamiast guzika "submit" jest obrazek na ktory trzeba kliknac zeby np. sie zalogowac? Tak jak to jest na poczta.onet.pl ? Przyklad z onet-u
<input document.login.ok.value=1 type=image src="_d/im/bok.gif">
Z gory dziekuje za odpowiedzi, pozdrawiam

nie wierze, ze nikt nie wie
Ten post edytował MiChaSSs 3.11.2008, 19:44:24