2011-11-18 69 views
-1

我正在嘗試閱讀非公開Goog​​le網站頁面的內容。我編寫了PHP腳本來閱讀公共Google Sites頁面,因此它使用了php的file_get_content()。使用PHP訪問(非公開)Google協作平臺網頁

有沒有辦法登錄php腳本,以便能夠訪問非公開的Google協作平臺頁面?

+0

您可以使用捲曲來發表您的登錄憑據,然後讓你從捲曲結果所需要的網頁 – danneth

回答

0

找到一些舊的代碼,做了類似的事情。應該讓你開始

/* Prepare cURL */ 
$ch = curl_init(); 

// set these according to the login form 
$login_query = http_build_query(
        array('username'=> 'username', 
         'password' => 'your_password', 
         'login' => 'log in')); 

/* Set options */ 
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com'); 
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com'); //set this to whatever the normal login does 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); //set to something resonable 
curl_setopt($ch, CURLOPT_TIMEOUT, 120); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt'); // make sure directory is writable 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_query); 
curl_setopt($ch, CURLOPT_POST, 1); 

$urlcontent = utf8_encode(curl_exec($ch)); 
$curl_info = curl_getinfo($ch); 

// at this point you are logged in... get your page 

/* Initiate cURL request */ 
curl_setopt($ch, CURLOPT_URL, 'www.yourpage.com/what-you-want'); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_REFERER, 'www.yourpage.com'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookie.txt'); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookie.txt'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

/* Send cURL request */ 
$result_data = utf8_encode(curl_exec($ch)); 
$curl_info = curl_getinfo($ch); 

/* Close cURL */ 
curl_close($ch); 

/* Handle result if any */ 
if ($this->curl_info['http_code'] == 200) 
{ 
    // at this point your page is in $result_data 
} 
0

如果您想要訪問需要某種帖子,會話或任何內容的頁面,我建議您使用CURL而不是file_get_contents。你可以在the documentation上閱讀更多關於它的信息。

如果它適用於Google非公開頁面,則不確定。它可以變成一個很大的挑戰,但:-)

相關問題