PHP 웹 스크래퍼 만들기 : guzzle + dom-crawler
PHP 웹 크롤러 또는 스크래퍼를 만들 때 guzzle 과 dom-crawler 조합으로 구현할 수 있습니다.
설치는 컴포저를 이용하는 것이 좋겠죠?
[code]
composer require guzzlehttp/guzzle
composer require symfony/dom-crawler
[/code]
잘 되는지 간단히 테스트해 볼까요?
[code]
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;
$client = new Client();
$response = $client->request('GET', 'http://example.com');
$html = (string) $response->getBody();
$crawler = new Crawler($html);
$links = $crawler->filter('a')->each(function (Crawler $node, $i) {
return $node->attr('href');
});
var_dump($links);
[/code]
궁금하신 부분이 있으시면 댓글로 남여 주세요.
오늘도 즐거운 코딩 하세요~~^^
댓글 1개
1년 전
요새 크롤링 쓸만한게 많은가요? 크롤링 너무 안한지 오래 되어서요
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5246 | node.js |
swallow
|
2년 전 | 1106 | |
| 5245 | PHP |
swallow
|
2년 전 | 2528 | |
| 5244 | PHP |
swallow
|
2년 전 | 1287 | |
| 5243 | JavaScript |
swallow
|
2년 전 | 687 | |
| 5242 | node.js |
swallow
|
2년 전 | 667 | |
| 5241 | node.js |
swallow
|
2년 전 | 779 | |
| 5240 | MySQL |
swallow
|
2년 전 | 808 | |
| 5239 | MySQL | 2년 전 | 785 | ||
| 5238 | JavaScript | 2년 전 | 983 | ||
| 5237 | 웹서버 |
swallow
|
2년 전 | 3991 | |
| 5236 | PHP |
swallow
|
2년 전 | 900 | |
| 5235 | PHP |
swallow
|
2년 전 | 1379 | |
| 5234 | 기타 | 2년 전 | 763 | ||
| 5233 | jQuery |
swallow
|
2년 전 | 2037 | |
| 5232 | 2년 전 | 619 | |||
| 5231 | 2년 전 | 1174 | |||
| 5230 | 2년 전 | 1077 | |||
| 5229 | PHP |
swallow
|
2년 전 | 1025 | |
| 5228 | MySQL | 2년 전 | 727 | ||
| 5227 | PHP |
swallow
|
2년 전 | 838 | |
| 5226 | PHP |
swallow
|
2년 전 | 1814 | |
| 5225 | PHP | 2년 전 | 576 | ||
| 5224 | node.js |
swallow
|
2년 전 | 4084 | |
| 5223 | PHP |
swallow
|
2년 전 | 1317 | |
| 5222 | 기타 |
techstar
|
2년 전 | 563 | |
| 5221 | PHP | 2년 전 | 653 | ||
| 5220 |
swallow
|
2년 전 | 906 | ||
| 5219 | 2년 전 | 881 | |||
| 5218 | 2년 전 | 524 | |||
| 5217 | 2년 전 | 1001 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기