Diğer siteden post veri PHP kullanarak ve tasarruf çıkış

0 Cevap php

Ben http://www.woorank.com arama sonuçlarından bilgi kurtarmaya çalışıyorum. Site popüler siteler için verileri önbelleğe alır, ancak çoğu için bunu bir rapor verir önce bir arama yapmanız gerekir. Yani bu çalıştı:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.woorank.com/en/report/generate');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('url'=>'hellothere.com'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);

(Bu ziyaret ne zaman gibi size aramalıdır sonra gibi, http://www.woorank.com/en/www/hellothere.com yönlendirmek için (curl çıkışına dayalı) gibi görünüyor, ama bir rapor oluşturmak değildir ve sadece hiçbir rapor henüz devletler url doğrudan).

Ben yanlış bir şey yapıyorum? Yoksa bu bilgi almak mümkün değil mi?

Update

İstek başlıkları: http://pastebin.com/3ijZfMmF

(Request-Line) POST /en/report/generate HTTP/1.1
Host    www.woorank.com
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://www.woorank.com/
Cookie  __utma=201458455.1161920622.1291713267.1291747441.1291773488.4; __utmc=201458455; __utmz=201458455.1291713267.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=201458455.1.10.1291773488
Content-Type    application/x-www-form-urlencoded
Content-Length  16

Ben test script gelen istek başlıklarını almak için nasıl emin değilim, ama bunu kullanarak:

curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$headers = curl_getinfo($ch);

$headers var içerir:

Array
(
    [url] => http://www.woorank.com/en/www/someothersite.com
    [content_type] => text/html; charset=UTF-8
    [http_code] => 200
    [header_size] => 841
    [request_size] => 280
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 1
    [total_time] => 0.904581
    [namelookup_time] => 3.2E-5
    [connect_time] => 3.3E-5
    [pretransfer_time] => 3.7E-5
    [size_upload] => 155
    [size_download] => 5297
    [speed_download] => 5855
    [speed_upload] => 171
    [download_content_length] => 5297
    [upload_content_length] => 0
    [starttransfer_time] => 0.242975
    [redirect_time] => 0.577306
    [request_header] => GET /en/www/someothersite.com HTTP/1.1
Host: www.woorank.com
Accept: */*
)

Bu arama formu gönderildikten sonra olur yönlendirme olduğunu bana görünüyor. Ama bu üstbilgileri görünür olmadığı hiçbir POST hiç, ya da emin değilim. Bu işe yaramazsa yana ama, ben bu eski tahmin ediyorum.

curl_exec gelen çıkış, sadece http://www.woorank.com/en/www/someothersite.com gelen HTML.

Update 2

Ben kullanarak kıvırmak isteğine başlıkların bazı ekleme çalıştı:

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

ve örneğin,

$headers = array( 
  "Host: www.woorank.com",
  "Referer: http://www.woorank.com/"
);

Bu formu POST yapmak, ama şimdi curl_exec yanıt başlıklarını gösteriyor değil. İşte fark bu:

Firefox, siteden yanıt başlıkları:

HTTP/1.1 302 Found
Date    Wed, 08 Dec 2010 02:19:18 GMT
Server  Apache/2.2.9 (Fedora)
X-Powered-By    PHP/5.2.6
Set-Cookie  language=en; expires=Wed, 08-Dec-2010 03:19:18 GMT; path=/
Set-Cookie  generate=somesite.com; expires=Wed, 08-Dec-2010 03:19:19 GMT; path=/
Location    /en/www/somesite.com
Cache-Control   max-age=1
Expires Wed, 08 Dec 2010 02:19:19 GMT
Vary    Accept-Encoding,User-Agent
Content-Encoding    gzip
Content-Length  20
Keep-Alive  timeout=1, max=100
Connection  Keep-Alive
Content-Type    text/html; charset=UTF-8

ve test.php gelen:

HTTP/1.1 302 Found
Date: Wed, 08 Dec 2010 02:27:21 GMT
Server: Apache/2.2.9 (Fedora)
X-Powered-By: PHP/5.2.6
Set-Cookie: language=en; expires=Wed, 08-Dec-2010 03:27:21 GMT; path=/
Set-Cookie: generate=someothersite.com; expires=Wed, 08-Dec-2010 03:27:22 GMT; path=/
Location: /en/www/someothersite.com
Cache-Control: max-age=1
Expires: Wed, 08 Dec 2010 02:27:22 GMT
Vary: Accept-Encoding,User-Agent
Content-Length: 0
Keep-Alive: timeout=1, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

Sadece fark Content-Encoding gzip ve Content-Length 20 testte eksik. Ne demektir biliyor ama eklerken etmeyin: başlıklarına "Content-Length 20" it "HTTP/1.1 413 Talep Çok Büyük" diyor ve bir şey yapmaz; "Content-Encoding: gzip" ekleyerek (: "<ÍXésÚ8ÿœüZíì &] ì º G" æè1 Mmu ... "bu gibi görünüyor bu yana, ben varsayalım) bu HTML GZipped dönüş yapar.

Bu bilgi yardımcı olur umarım.

0 Cevap