Puppeteer의 괴롭힘
8032 단어 puppeteer
속도를 높이고 싶을 때
HTML을 얻을 수 있으면 좋을 때
setRequestInterception에서 요청을 처리하는 방법을 제어합니다.request.abort에서 처리를 중단하고 request.continue에서 처리를 계속시키는 제어를 할 수 있다.
HTML만 있으면 좋다고 하는 때는 이하로 말하는 최초의 리퀘스트만 있으면 좋다.

그러니 그냥 얻으면 OK
let page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
if (url === interceptedRequest.url()) {
interceptedRequest.continue();
} else {
interceptedRequest.abort();
}
});
launch 때 할 무언가
다양한 인수를 부여하는 것이 좋습니다.
puppeteer.launch({
headless: true,
args: [
'--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process'
]
})
더 이상 Puppeteer는 상관없는 무언가
병렬로 처리하기만 하면
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: []
});
const verifyExistParts (browser, url) => {
...
return true or false
}
await Promise.all(urls.map(url => verifyExistParts(browser, url))).then((results) => {
const failures = results.filter(e => e === false).length;
const msg = `${results.length} examples, ${failures} failures`;
let status;
if (results.every(result => result)) {
status = 'Succeeded.';
} else {
status = 'Failed.';
}
console.log(`${status} ${msg}`);
});
browser.close();
})();
launch 할 때 여러 가지
options
품목
설명
비고 |
headless
Chrome을 크롬(브라우저 UI) 없이 실행합니다. 기본적으로 true
참고 URL
ignoreHTTPSErrors
오류를 무시할 수 있습니다. 기본값은 false
slowMo
ms 단위로 지연 실행해 준다
args
브라우저 인스턴스에 전달할 추가 인수
timeout
브라우저 인스턴스가 시작되기를 기다리는 최대 시간(ms)입니다. 기본값은 30000ms입니다. 0에서 사용 불가능
args
조금 너무 많아 좌절
품목
설명
비고 |
--disable-gpu
GPU hardware acceleration 사용 안 함
--disable-dev-shm-usage
컨테이너에서 실행할 때는 메모리 관계상 부여하는 것이 좋다.
참고 URL
--no-sandbox
보통 sandbox ※화되어 있는 모든 프로세스 타입에 대해 sandbox를 무효로 한다
sandbox : 외부에서받은 프로그램을 보호 된 영역에서 실행하여 시스템이 무단으로 작동하는 것을 방지하는 보안 시스템
Reference
이 문제에 관하여(Puppeteer의 괴롭힘), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/hanaclover/items/952db8aa4023d18e76ce
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
let page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
if (url === interceptedRequest.url()) {
interceptedRequest.continue();
} else {
interceptedRequest.abort();
}
});
puppeteer.launch({
headless: true,
args: [
'--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process'
]
})
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: []
});
const verifyExistParts (browser, url) => {
...
return true or false
}
await Promise.all(urls.map(url => verifyExistParts(browser, url))).then((results) => {
const failures = results.filter(e => e === false).length;
const msg = `${results.length} examples, ${failures} failures`;
let status;
if (results.every(result => result)) {
status = 'Succeeded.';
} else {
status = 'Failed.';
}
console.log(`${status} ${msg}`);
});
browser.close();
})();
options
품목
설명
비고 |
headless
Chrome을 크롬(브라우저 UI) 없이 실행합니다. 기본적으로
true참고 URL
ignoreHTTPSErrors
오류를 무시할 수 있습니다. 기본값은
falseslowMo
ms 단위로 지연 실행해 준다
args
브라우저 인스턴스에 전달할 추가 인수
timeout
브라우저 인스턴스가 시작되기를 기다리는 최대 시간(ms)입니다. 기본값은
30000ms입니다. 0에서 사용 불가능args
조금 너무 많아 좌절
품목
설명
비고 |
--disable-gpu
GPU hardware acceleration 사용 안 함--disable-dev-shm-usage
컨테이너에서 실행할 때는 메모리 관계상 부여하는 것이 좋다.
참고 URL
--no-sandbox
보통 sandbox ※화되어 있는 모든 프로세스 타입에 대해 sandbox를 무효로 한다
sandbox : 외부에서받은 프로그램을 보호 된 영역에서 실행하여 시스템이 무단으로 작동하는 것을 방지하는 보안 시스템
Reference
이 문제에 관하여(Puppeteer의 괴롭힘), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hanaclover/items/952db8aa4023d18e76ce텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)