Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

chrome headless 모드를 이용하여 랜더링된 html 소스 가져오기 #2

2017-08-22 by 편리

혼란하다. 혼란해!!

지난 번 포스트를 바탕으로 좀 더 기능 개선을 거친 버전이라고 할 수 있을 것 같다. 실제 서비스로 사용하기에는 어떨지 모르겠지만.. 브라우저로 접속해서 입력한 url 페이지에 접속해서 html 소스를 가져오도록 했다. nodejs와 기타 여러 모듈을 사용했는데.. nodejs는 책을 한 줄도 보지 않았기 때문에 뭔 소리인지 모르겠다.

우선 nodejs와 기타 모듈 설치를 진행한다.

$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
$ sudo apt install nodejs
$ sudo npm install chrome-launcher
$ sudo npm install chrome-remote-interface
$ sudo npm install pretty
$ sudo npm install yargs

(more…)

Continue Reading

chrome headless 모드를 이용하여 랜더링된 html 소스 가져오기

2017-08-18 by 편리

vus.js 등의 자바스크립트를 이용하여 웹페이지의 화면을 구성하는 경우가 많은데 이럴 경우 일반적인 방법으로는 실제 사용자가 보는 화면의 html 소스를 가져올 수가 없다. PhantomJS 등을 이용해서 처리를 할 수가 있으나 리눅스 크롬브라우저 59 버전부터는 headless 모드를 지원하기 때문에 이를 이용해서 랜더링된 페이지의 html 소스를 가져오기로 한다. 두 가지 방법을 시도했으며 각자의 선택으로 적당한 방법을 선택하면 된다.

–dump-dom 옵션을 이용한 방법

별도의 작업없이 크롬 설치만으로 사용할 수 있는 방법이다.

$ /usr/bin/google-chrome --headless --disable-gpu --dump-dom "http://example.com"

–disable-gpu 옵션은 최신 버전에서는 필요하지 않으나 오류가 발생한다면 추가하도록 한다. html 소스 코드를 파일로 저장하려면 위 명령어 끝에 > file.html 과 같이 추가한다. PHP를 이용하여 실행하기 위해서는 아래와 같이 코드를 작성한다.

<?php
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING );

$url = 'http://example.com';

function getRenderedContent($url) {
    $out = exec('/usr/bin/google-chrome --headless --disable-gpu --dump-dom "'.$url.'" &', $output);

    return $output;
}

$output = getRenderedContent($url);

print_r(implode("\n", $output));

자료
– https://blog.outsider.ne.kr/1291
– https://developers.google.com/web/updates/2017/04/headless-chrome

(more…)

Continue Reading

아마존마케팅툴(amazonmarketingtool.com) 개발

2017-08-02 by 편리

아마존마케팅툴 : https://amazonmarketingtool.com/

지금의 회사로 이직한지 만 4개월이 됐다. 처음엔 뭔가 정신도 없고 회사 분위기도 기존과는 달랐기 때문에 어떻게 해야할지 난감하거나.. 혼란스러운 시간을 보내고 있을 때 아마존마케팅툴(이하 AMT)의 개발을 맡게 됐다. 그 전까지는 아마존을 사용해본 적도 없고 더구나 셀러도 아니었기 때문에 회의에서 오고가는 용어조차 모두 외계어로 들릴 때였는데.. 혼란스러운 틈을 타서 개발을 시작하게 됐으니.. 사실 근심걱정이 가득했다. 그러나 회사에서 시간은 잘 갔으니.. 어쨌든 쌤쌤???

1차버전은 아마존에서 셀러가 설정한 키워드의 인덱싱 여부를 Batch 작업으로 확인할 수 있는 기능과 입력한 키워드 중 중복되는 단어를 제거하고 1,000글자씩 나눠서 출력하는 기능을 개발했다. 개념자체는 간단했고 개발 작업도 그렇게 어렵지는 않았다. 아마존 API에서 너무 빠른 접속은 차단한다는 것을 알기 전까지는… API 접속 차단이슈가 나오면서 방향을 다시 잡기 시작했다. AJAX 콜을 순차적으로 처리하는 것으로 정하고 관련 자료를 검색 후 다시 개발을 했다. AJAX 콜을 순차적으로 처리할 수 있는 Queue 플러그인이 개발되어 공개돼 있다는 것이 얼마나 기쁜 일이었는지… (more…)

Continue Reading

[PHP] Payoneer 결제 API

2017-07-31 by 편리

Payoneer의 예치금을 이용해 결제를 처리할 수 있는 API이다. Payoneer 파트너사에 가입하고 지불처리하는 것이 주된 기능이다.

<?php
/**
 * @Author: Seongho Jang
 * @Date:   2017-07-21
 * @Last Modified by:   Seongho Jang
 * @Last Modified time: 2017-07-21 17:33:27
*/

class Payoneer
{
    const SANDBOX_API_URL    = 'https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx';
    const PRODUCTION_API_URL = 'https://api.payoneer.com/payouts/HttpAPI/API.aspx';

    public $apiEndpoint;    
    public $apiUser;    
    public $apiPassword;
    public $partnerId;
    public $sandbox = true;
    
    private $response;
    private $params;
    
    function __construct($apiUser, $apiPassword, $partnerId, $sandbox = true) {
        $this->sandbox = $sandbox;
        if($sandbox == true){
            $this->apiEndpoint = static::SANDBOX_API_URL;    
        }
        else{
            $this->apiEndpoint = static::PRODUCTION_API_URL;
        }
        
        $this->apiUser = $apiUser;
        $this->apiPassword = $apiPassword;
        $this->partnerId = $partnerId;
    }

    public function getBasicParameters() {
        return ['p1' => $this->apiUser, 'p2' => $this->apiPassword, 'p3' => $this->partnerId];
    }

    public function getToken($request)
    {
        $this->call('GetToken', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function getTokenXML($request)
    {
        $this->call('GetTokenXML', $request);
        $response = $this->response;
        return $this->getData('Token');
    }

    public function getApiStatus($item='')
    {
        $this->call('Echo');
        
        return $this->getData($item);
    }

    public function getVersion()
    {
        $this->call('GetVersion');
        $response = $this->response;
        return $this->getData('Version');
    }

    public function chargeAccount($request)
    {
        $this->call('ChargeAccount', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function cancelChargeAccount($request)
    {
        $this->call('CancelChargeAccount', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function getPaymentStatus($request)
    {
        $this->call('GetPaymentStatus', $request);
        $response = $this->response;
        return $this->getData();
    }

    public function convertArray($object)
    {
        return json_decode( json_encode( $object ), 1 );
    }

    public function getData($key='')
    {
        $xml = simplexml_load_string($this->response);

        $data = $this->convertArray($xml);

        if($key)
            return $data[$key];
        else
            return $data;
    }

    public function call($methodName, $request=null)
    {
        $this->params = $this->getBasicParameters();

        if($request && is_array($request))
            $this->params = array_merge($this->params, $request);

        $url = $this->apiEndpoint.'?mname='.$methodName;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
        
        $this->response = curl_exec($ch);
        $err = curl_error($ch);

        curl_close($ch);
    }
}

(more…)

Continue Reading

[PHP] xml 포맷의 데이터를 배열(Array)로 변환

2017-07-21 by 편리

curl 등을 사용해 API 콜을 보내고 리턴 받은 xml 포맷의 데이터를 배열(Array)로 변환하는 코드이다. <?php function convertArray($object) { return json_decode( json_encode( $object ), 1 ); } $url = ‘http://api.example.com/xml’; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_ENCODING, ‘gzip,deflate’); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_TIMEOUT, …

Posts pagination

  • Previous
  • 1
  • …
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • …
  • 748
  • Next

Recent Posts

  • SK 세븐모바일 유심 셀프교체
  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes