se-scraper/run.js

72 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-12-24 14:25:02 +01:00
const se_scraper = require('./index.js');
let config = {
// the user agent to scrape with
user_agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36',
// if random_user_agent is set to True, a random user agent is chosen
2019-01-27 20:08:09 +01:00
random_user_agent: true,
2018-12-24 14:25:02 +01:00
// how long to sleep between requests. a random sleep interval within the range [a,b]
// is drawn before every request. empty string for no sleeping.
sleep_range: '',
// whether to start the browser in headless mode
2019-06-11 18:16:59 +02:00
headless: true,
// whether debug information should be printed
// level 0: print nothing
// level 1: print most important info
// ...
// level 4: print all shit nobody wants to know
debug_level: 1,
// specify flags passed to chrome here
chrome_flags: [],
2019-01-26 20:15:19 +01:00
// path to output file, data will be stored in JSON
output_file: 'examples/results/baidu.json',
// whether to prevent images, css, fonts from being loaded
// will speed up scraping a great deal
2019-03-10 20:02:42 +01:00
block_assets: false,
2019-01-27 15:54:56 +01:00
// path to js module that extends functionality
// this module should export the functions:
// get_browser, handle_metadata, close_browser
// must be an absolute path to the module
//custom_func: resolve('examples/pluggable.js'),
custom_func: '',
// use a proxy for all connections
// example: 'socks5://78.94.172.42:1080'
// example: 'http://118.174.233.10:48400'
2019-01-30 23:53:09 +01:00
proxy: '',
// a file with one proxy per line. Example:
// socks5://78.94.172.42:1080
// http://118.174.233.10:48400
proxy_file: '',
// check if headless chrome escapes common detection techniques
// this is a quick test and should be used for debugging
test_evasion: false,
2019-03-10 20:02:42 +01:00
apply_evasion_techniques: true,
// log ip address data
log_ip_address: false,
// log http headers
log_http_headers: false,
puppeteer_cluster_config: {
timeout: 10 * 60 * 1000, // max timeout set to 10 minutes
monitor: false,
concurrency: 1, // one scraper per tab
maxConcurrency: 1, // scrape with 2 tabs
}
2018-12-24 14:25:02 +01:00
};
2019-06-11 18:16:59 +02:00
(async () => {
let scrape_config = {
// which search engine to scrape
search_engine: 'bing',
// an array of keywords to scrape
keywords: ['cat', 'mouse'],
// alternatively you can specify a keyword_file. this overwrites the keywords array
keyword_file: '',
// the number of pages to scrape for each keyword
num_pages: 2,
};
2018-12-24 14:25:02 +01:00
2019-06-11 18:16:59 +02:00
let results = await se_scraper.scrape(config, scrape_config);
console.dir(results, {depth: null, colors: true});
})();
2019-01-27 20:08:09 +01:00