added spider for segmentfault

This commit is contained in:
Marvin Zhang
2019-03-11 13:15:00 +08:00
parent 3aba022922
commit 0dc5c64bc1
2 changed files with 30 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

View File

@@ -0,0 +1,30 @@
const puppeteer = require('puppeteer');
(async () => {
const browser = await (puppeteer.launch({
timeout: 15000
}));
const url = 'https://segmentfault.com/newest';
const page = await browser.newPage();
await page.goto(url);
await page.waitFor(2000);
await page.screenshot({path: 'screenshot.png'});
const titles = await page.evaluate(sel => {
let results = [];
document.querySelectorAll('.news-list .news-item .news__item-title').forEach(el => {
results.push({
title: el.innerText
})
});
return results;
});
console.log(titles);
browser.close();
})();