2017-09-22 102 views
-1

我試圖解析淘寶,product card錯誤403禁止淘寶解析

的數據是here

在瀏覽器中,數據頁正常加載: enter image description here

enter image description here

但在過渡時我得到403禁止:

enter image description here

我怎樣才能解決這個限制使用PHP 幫助請,非常需要客戶抱怨

+0

請考慮增加一些相關的代碼,使我們能夠更好地幫幫我! – AlexKoren

回答

2

detailskip.taobao.com/json/dyn_combo.do會阻止沒有指向其他detailskip.taobao.com網址的「referrer」標頭的請求。請注意,引薦來源不一定是真實的,你可以僞造它,他們並沒有真正驗證它,頭部只是在那裏。另外,它們在用戶代理頭中用「php」來阻止任何請求。他們也阻止任何沒有用戶代理頭的請求。

示例代碼僞裝網址標頭和用戶代理,以獲得JSON(使用my hhb_curl library圍繞curl_功能的錯誤檢測包裝):

<?php 
declare(strict_types = 1); 
header ("content-type: text/plain;charset=utf8"); 
require_once ('hhb_.inc.php'); 
$json = (new hhb_curl ('', true))->setopt_array (array (
     CURLOPT_URL => 'https://detailskip.taobao.com/json/dyn_combo.do?itemId=556926591992&databiz=promotionPrice,upp,bonuscoupon,shopbonuscoupon,shopbonuscoupon,shopcoupon,sidebarcoupon,overseaNewDelivery,dynStock,overseaViewer,contract,activitySwitch,buycount', 
     CURLOPT_USERAGENT => 'curl/7.52.1', 
     CURLOPT_HTTPHEADER => array (
       'Referer: https://world.taobao.com/item/556926591992.html' 
     ) 
))->exec()->getStdOut(); 
echo $json; 
+0

爲什麼我會得到一個錯誤: 警告:不支持在/home/n/domen/domen/public_html/hhb_.inc中聲明'strict_types' .php on line 2 解析錯誤:語法錯誤,意外的':',期待'{'位於第9行的/home/n/domen/domen/public_html/hhb_.inc.php – newProgrammer

+0

@ newProgrammer因爲寫了這段代碼對於PHP7,並且您正試圖在PHP5中運行它。你真的應該升級,PHP7的提示是一個祝福 – hanshenrik

+0

如果運行,php7將有其他代碼段的問題 – newProgrammer

1

什麼是你無法分析,到底是什麼?我沒有問題,分析產品的價格和產品名稱,

<?php 
declare(strict_types = 1); 
$html = file_get_contents ('https://world.taobao.com/item/556926591992.html'); 
$domd = @DOMDocument::loadHTML ($html); 
$xp = new DOMXPath ($domd); 
$name = $xp->query ('//span[@itemprop="name"]')->item (0)->textContent; 
$price = trim (preg_replace ('/\s+/u', ' ', $xp->query ('//div[contains(@class,"price-show") and not(contains(@class,"hidden"))]')->item (0)->textContent)); 
var_dump ($name, $price); 

輸出:

string(82) "歐美高街bf風潮牌oversize寬鬆男女嘻哈hiphop套頭衛衣情侶裝外套" 
string(9) "¥ 189.00" 

(和普羅蒂普,捲曲將運行得更快,由於它的內容長度的瞭解而的file_get_contents只讀取,直到如果你使用了CURLOPT_ENCODING,curl會使用相當少的帶寬,因爲這個網站和curl支持file_get_contents不支持的gzip壓縮傳輸,curl不依賴於php.ini設置,file_get_contents需要)

+0

解析器不需要網站本身:'https:// world.taobao.com/item/556926591992.html'和數據源:'https:// detailskip.taobao.com/json/dyn_combo.do' – newProgrammer

+0

@ newProgrammer最有可能,https://world.taobao.com/item/556926591992.html生成一個獨特的csrf-token您必須下載並解析出html和一個cookie會話ID,並提供給https://detailskip.taobao.com/json/dyn_combo.do - 但是,您之後又會收到什麼數據? – hanshenrik

+0

所有這些數據:https://pp.userapi.com/c841226/v841226308/2273b/_yWRug4FwWU.jpg – newProgrammer