본문 바로가기

전체 글847

API를 이용한 롤 전적검색 사이트 만들기 라이엇에서 제공하는 API를 이용하여 간단한 전적검색 사이트를 만들어보자. 먼저 전에 작성한 글(http://hides.kr/370) 을 참고하여 API Key를 발급받는다. 그 다음 레벨/티어 등 기본적인 정보를 받아오는 API를 살펴봐야하는데 해당 API는 사용자의 닉네임이 아닌 닉네임을 통해 받아온 ID를 기준으로 값을 넘겨준다. 먼저 아래 URL을 통해 검색하고자 하는 사용자의 ID를 알아보자. https://kr.api.pvp.net/api/lol/kr/v1.4/summoner/by-name/사용자닉네임?api_key=API키 ID값을 알아냈으면 이제 사용자에 대한 정보를 제공해주는 API를 통해 정보를 받아오자. https://kr.api.pvp.net/api/lol/kr/v2.5/league.. 2016. 2. 27.
웹 파일 긁어오기 import shutilimport requests for i in range(1, 150): url = 'http://test.com/'+str(i)+'.png' response = requests.get(url, stream=True) with open('./champ/'+str(i)+'.png', 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response 2016. 2. 27.
Cannot use object of type stdClass as array 에러 json_decode 를 통하여 값에 접근하려고 할 때 위와 같은 에러가 발생하면 두번째 인자를 true로 주면 된다.(true로 줄 시 array로 반환됨) 2016. 2. 27.
php json 처리 $result = '{"Cancelled":false,"MessageID":"402f481b-c420-481f-b129-7b2d8ce7cf0a","Queued":false,"SMSError":2,"SMSIncomingMessages":null,"Sent":false,"SentDateTime":"\/Date(-62135578800000-0500)\/"}'; $json = json_decode($result, true); print_r($json);OUTPUTArray ( [Cancelled] => [MessageID] => 402f481b-c420-481f-b129-7b2d8ce7cf0a [Queued] => [SMSError] => 2 [SMSIncomingMessages] => [Sent] => [Se.. 2016. 2. 27.
PHP curl function httpGet($url){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);// curl_setopt($ch,CURLOPT_HEADER, false); $output=curl_exec($ch); curl_close($ch); return $output;} echo httpGet("http://naver.com"); 2016. 2. 26.
PHP 소켓 function http_get($host, $path, $data, $cookie) {$http_response = "";$fp = fsockopen($host, 80); fputs($fp, "GET ".$path." HTTP/1.1\r\n");fputs($fp, "Host: ".$host."\r\n");fputs($fp, "User-Agent: ".$_SERVER["HTTP_USER_AGENT"]."\r\n");fputs($fp, "Referer: http://".$host.$path."\r\n");fputs($fp, "Cookie: ".$cookie."\r\n");fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");fputs($fp,.. 2016. 2. 26.