parent
e0a032f03b
commit
8a60e0712b
1 changed files with 31 additions and 0 deletions
@ -0,0 +1,31 @@ |
||||
'use strict'; |
||||
|
||||
const axios = require( 'axios' ); |
||||
const jsdom = require( 'jsdom' ); |
||||
const { JSDOM } = jsdom; |
||||
|
||||
const fs = require( 'fs' ); |
||||
const path = require( 'path' ); |
||||
|
||||
axios.get( 'https://us.pg.com/brands/' ) |
||||
.then( function( response ) { |
||||
let content = response.data; |
||||
const dom = new JSDOM( content ); |
||||
|
||||
let brands_props = dom.window.document.querySelector( '[data-react-component="BrandContainer"]' ) |
||||
.getAttribute( 'data-react-props' ); |
||||
|
||||
if ( brand_props ) { |
||||
fs.writeFile( path.resolve( __dirname, './../data/props.json' ), brands_props, function( err, data ) { |
||||
if ( err ) { |
||||
return console.log( err ); |
||||
} |
||||
}); |
||||
} |
||||
else { |
||||
console.log( 'brands data was not found' ); |
||||
} |
||||
}) |
||||
.catch( function( error ) { |
||||
console.log( error ); |
||||
}); |
Loading…
Reference in new issue