2017-12-04 2 views
0

www.dotabuff.com에서 증기 ID 목록에 대한 데이터를 검색하려고하는데 "대신 찾고있는 정보를 찾을 수 없습니다. ! ".CURL에서이 웹 사이트의 데이터를 가져 오지 못합니다.

목표는 웹 사이트로 이동하여 스팀 ID로 플레이어를 검색하고 승리율을 추출하는 것입니다.

(이것은 매우 작은 목록 용으로, 도트 패드를 사용하지 않아도됩니다.) 여기

는 (정적 스팀 ID와 예) 내 코드입니다 :

//create array of data to be posted 
$post_data['utf8'] = '✓'; 
$post_data['q'] = '76561198055615656'; 
$post_data['commit'] = 'Search'; 

//traverse array and prepare data for posting (key1=value1) 
foreach ($post_data as $key => $value) { 
$post_items[] = $key . '=' . $value; 
} 

//create the final string to be posted using implode() 
$post_string = implode ('&', $post_items); 

//create cURL connection 
$curl_connection = 
curl_init('https://www.dotabuff.com//'); 

//set options 
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 

//set data to be posted 
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); 

//perform our request 
$result = curl_exec($curl_connection); 
echo $result; 

//close the connection 
curl_close($curl_connection);  
+0

이 페이지를 스크랩하거나 API로 사용 하시겠습니까? 페이지 또는 API 문서를 게시하십시오. –

+0

빠른 검색 [TOS에 대한 가능성이 가장 높은 임의의 페이지를 스크랩하는 대신 Valve의 공식 Dota2 일치 내역 API를 사용하는 것이 좋습니다] (https://dev.dota2.com/showthread.php?t=47115). – orhtej2

답변

0

당신은 검색을 수행 컬과 POST를 사용하지만, 검색 양식 GET을 사용하는 Dotabuff 웹 사이트에서 찾고있다, 그래서 웹 사이트가 POST vars 대신 GET vars를 찾고 있다고 의심하십시오. 나는 이것을 테스트하지는 않았지만 https://www.dotabuff.com/search?q=76561198055615656 (POSTFIELDS없이)의 컬 요청을 제안하고 그 결과를 확인하십시오.

0

URL없이 초기화하거나 GET 버전의 URL을 조합하여 사이트에 게시하십시오.

예를 들어 사용자 'USH!'에 대한 정보를 원하면 (나는 무작위로 하나를 선택했다.) 당신이 합성하려는 URL은 다음과 같이 보일 것이다 :

https://www.dotabuff.com/search?utf8=%E2%9C%93&q=USH%21&button= 

I의는 GET URI 안전 문자열로 플레이어 ID를 변환하기를 urlencode를 사용하는 것이 좋습니다

예 :

$safe_player_id = urlencode($player_id) 

$URI = sprintf("https://www.dotabuff.com/search?q=%s&button=",$safe_player_id); 

또는, 경우 플레이어 ID 코드 (int)를 알고 있으면 통계 페이지 (이 작동)를 얻을 수 있습니다 (이 작동) :

https://www.dotabuff.com/players/76561198055615656 

Th 그냥 원하는 페이지를 파싱하면됩니다.

관련 문제