2013-04-10 112 views
1

我正在研究抓取腳本來讀取網上商店的評分。php cURL忽略url中的變量

捲曲部分現在讓我感到困難,因爲它沒有檢索正確的內容。

我使用ajax腳本批量選擇數據庫中的URL。我將捲曲正確的URL給予帶有評分的頁面,但Curl正在檢索網頁中沒有可變部分的頁面。

這是我傳遞到捲曲的網址:$actualurl

http://www.domain.com/epages/xxx.sf/de_DE/?ObjectPath=/Shops/15456062/Products/%22Briefkastenst%C3%A4nder%20Bobiround%22/SubProducts/%22Briefkastenst%C3%A4nder%20Bobiround%20gr%C3%BCn%20RAL6005%22&ViewAction=ViewProductRating

(這是我想讀的所有6個等級(Produktbewertungen)的頁面)

但隨着捲曲呼叫我從這個頁面獲取內容,這是相同的沒有viewAction,我呼應輸出

http://www.domain.com/epages/xxx.sf/de_DE/?ObjectPath=/Shops/15456062/Products/%22Briefkastenst%C3%A4nder%20Bobiround%22/SubProducts/%22Briefkastenst%C3%A4nder%20Bobiround%20gr%C3%BCn%20RAL6005%22

我的捲曲調用如下:

  $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
      curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch, CURLOPT_URL, $actualurl);    
      //read content of $url 
      $result = curl_exec ($ch); 
      curl_close ($ch); 

爲什麼捲曲忽略了URL的最後一部分(用&ViewAction=ViewProductRating

太感謝你了,我還是新的捲曲!

EDIT

我建立從4份上述URL。該部分如下:

$domainroot: http://www.domain.com/ 
$objectpath: epages/xxx.sf/de_DE/?ObjectPath 
$ratingurl: %3D%2FShops%2F15456062%2FProducts%2F%2522Briefkastenst%25C3%25A4nder%2520Bobiround%2522%2FSubProducts%2F%2522Briefkastenst%25C3%25A4nder%2520Bobiround%2520gr%25C3%25BCn%2520RAL6005%2522%26amp%3B 
$viewratings: ViewAction=ViewProductRating 

,最後我把它們連在一起:

$actualurl = $domainroot.$objectpath.$ratingurl.$viewratings; 
+0

看起來好像CURLOPT_POST標誌是活動的,雖然你沒有設置它... – Borniet 2013-04-10 06:14:27

+0

echo curl_error($ ch);,你會得到「畸形」 – Shin 2013-04-10 06:19:13

+0

@shin我試過了,但它什麼都沒輸出。 – Owl 2013-04-10 07:28:31

回答

0

太謝謝你了您的幫助!你讓我今天一整天都感覺很好!

感謝任何試圖幫助的人!

這確實是&人物搞砸了。不知不覺中,這些腳本有進入該數據庫的URL時&到&,這不得不改回

$ratingurl = str_replace('&','&',$ratingurl); 

的URL最初獲取與preg_match_all和直接進入數據庫

1

您的查詢字符串的第一個參數應正確編碼:

$queryString = 'ObjectPath=%2FShops%2F15456062%2FProducts%2F%22Briefkastenst' .  
'%C3%A4nder+Bobiround%22%2FSubProducts%2F%22Briefkastenst' . 
'%C3%A4nder+Bobiround+gr%C3%BCn+RAL6005' 
'&ViewAction=ViewProductRating'; 
+0

謝謝。我從4部分(域+第一部分+數據庫部分+ viewActionpart)設置URL,我試圖在第一部分和數據庫部分創建一個urlencode,但現在在服務器上找不到該URL。我必須編碼哪些部分?奇怪,因爲我認爲它編碼正確 – Owl 2013-04-10 07:34:53

+0

嗯奇怪我不明白這個答案,我試圖編碼你說的部分,但它的結果總是作爲網站找不到從服務器。 – Owl 2013-04-10 08:02:44

+0

你怎麼稱呼數據庫部分和你的例子的第一部分?您需要對在查詢字符串中作爲參數傳遞的任何值進行編碼(在解碼任何已編碼的值之後使用urlencode)。 已提供的編碼示例如下(因爲ObjectPath參數值已被部分編碼): '$ objectPathValue = urlencode(urldecode('/ Shops/15456062/Products /%22Briefkastenst%C3%A4nder%20Bobiround%22/SubProducts /%22Briefkastenst%C3%A4nder%20Bobiround%20gr%C3%BCn%20RAL6005%22'));' – 2013-04-10 08:34:49