2018-12-24 14:25:02 +01:00
|
|
|
const se_scraper = require('./index.js');
|
2019-01-27 15:54:56 +01:00
|
|
|
const resolve = require('path').resolve;
|
2018-12-24 14:25:02 +01:00
|
|
|
|
|
|
|
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
|
|
|
// get meta data of scraping in return object
|
2019-01-26 20:15:19 +01:00
|
|
|
write_meta_data: false,
|
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.
|
2019-01-29 22:48:08 +01:00
|
|
|
sleep_range: '[1,2]',
|
2018-12-24 14:25:02 +01:00
|
|
|
// which search engine to scrape
|
2019-01-31 22:13:22 +01:00
|
|
|
search_engine: 'marketwatch',
|
2018-12-24 14:25:02 +01:00
|
|
|
// whether debug information should be printed
|
2019-01-27 15:54:56 +01:00
|
|
|
// debug info is useful for developers when debugging
|
2019-01-30 23:53:09 +01:00
|
|
|
debug: false,
|
2018-12-24 14:25:02 +01:00
|
|
|
// whether verbose program output should be printed
|
2019-01-27 15:54:56 +01:00
|
|
|
// this output is informational
|
2019-01-30 16:05:08 +01:00
|
|
|
verbose: true,
|
2018-12-24 14:25:02 +01:00
|
|
|
// an array of keywords to scrape
|
2019-01-31 22:13:22 +01:00
|
|
|
keywords: ['MSFT', 'AAPL'],
|
2019-01-24 15:50:03 +01:00
|
|
|
// alternatively you can specify a keyword_file. this overwrites the keywords array
|
2019-01-26 20:15:19 +01:00
|
|
|
keyword_file: '',
|
2019-01-29 22:48:08 +01:00
|
|
|
// the number of pages to scrape for each keyword
|
2019-01-31 14:57:34 +01:00
|
|
|
num_pages: 1,
|
2019-01-24 15:50:03 +01:00
|
|
|
// whether to start the browser in headless mode
|
2019-01-31 14:57:34 +01:00
|
|
|
headless: false,
|
2019-01-26 20:15:19 +01:00
|
|
|
// path to output file, data will be stored in JSON
|
2019-01-30 23:53:09 +01:00
|
|
|
output_file: '',
|
2019-01-27 01:27:52 +01:00
|
|
|
// whether to prevent images, css, fonts from being loaded
|
|
|
|
// will speed up scraping a great deal
|
2019-01-27 15:54:56 +01:00
|
|
|
block_assets: true,
|
|
|
|
// 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'),
|
2019-01-29 22:48:08 +01:00
|
|
|
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: '',
|
2018-12-24 14:25:02 +01:00
|
|
|
};
|
|
|
|
|
2019-01-27 20:08:09 +01:00
|
|
|
function callback(err, response) {
|
2018-12-24 14:25:02 +01:00
|
|
|
if (err) { console.error(err) }
|
|
|
|
|
|
|
|
/* response object has the following properties:
|
|
|
|
|
|
|
|
response.results - json object with the scraping results
|
|
|
|
response.metadata - json object with metadata information
|
|
|
|
response.statusCode - status code of the scraping process
|
|
|
|
*/
|
|
|
|
|
2019-01-30 20:24:03 +01:00
|
|
|
// console.dir(response.results, {depth: null, colors: true});
|
2019-01-27 20:08:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
se_scraper.scrape(config, callback);
|