2016-11-29 130 views
-3

將網站價格轉化爲應用程序的最佳方法是什麼?價格沒有交付給我,因此我需要一種方法來自動搜索每天在應用程序中使用的網站的產品及其價格。建立應用程序的軟件還沒有決定:)從網站拖網數據

+0

這是一個荒謬的模糊和過於籠統的問題。請將您的問題重點放在特定的技術問題上。首先讓自己瞭解你想要做什麼,瞭解可用的解決方案,一旦你有了一些代碼,你需要有人來幫助你,然後來到這裏。但總是至少嘗試在網上找到答案,如果已經可用,因爲多餘地詢問答案或已經回答了初學者問題。 – clearlight

回答

0

我使用curl在PHP中從特定的網頁中獲取特定數據。 所以我的webapp在我的服務器上調用一個php腳本來獲取來自特定網頁的數據。

以下代碼利用e-pages.dk中的一個功能重定向到最新的報紙,然後代碼捕獲最新報紙的編號並將該編號返回給調用的webapp(代碼未顯示)。

$urltopost = 'http://www.e-pages.dk/vesthimmerlandsavis/'; 
$ch = curl_init($urltopost); 
curl_setopt($ch, CURLOPT_URL, $urltopost); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$log->write('URL: '.$urltopost, __FILE__, __LINE__); 
$response = curl_exec($ch); 
// Catch redirection 
if (preg_match('#Location: (.*)#', $response, $matches)) 
{ 
    $redirect = trim($matches[1]); 
    // $redirect = '/vesthimmerlandsavis/472' 
    $log->write('Redirection: '.$redirect, __FILE__, __LINE__); 
} 
else 
{ 
    die('Could not find newest newspaper'); 
} 

// Catch number in /vesthimmerlandsavis/472 
preg_match_all($pattern, $redirect, $matches); 
$currentNumber = $matches[0][0]; 
$log->write('Current number: '.$currentNumber, __FILE__, __LINE__);