• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/site/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/site/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/site/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to write to a text file Javascript?

I am attempting to write a webScrape to a text file and it just isn't working. All the text file says is object over and over again. Any help will be much appreciated, i am relatively new to this type of programming and i'm coming up blank!

EDIT: I now have the text file working but i'm wondering how i can to a line break after each line of data is added.

 const axios = require('axios'); const cheerio = require('cheerio'); const camelCase = require('camelcase'); // added this for readale properties const fs = require('fs')   // use async / await feature async function scrape(url) {      // get html page     const { data } = await axios.get(url);      // convert html string to cheerio instance     const $ = cheerio.load(data);      // query all list items     return $('.tabular-data-panel > ul')         // convert cheerio collection to array for easier manipulation         .toArray()         // transform each item into proper key values         .map(list => $(list)             // query the label element             .find('.panel-row-title')             // convert to array for easier manipulation             .toArray()             // use reduce to create the object             .reduce((fields, labelElement) => {                 // get the cheerio instance of the element                 const $labelElement = $(labelElement);                 // get the label of the field                 const key = $labelElement.text().trim();                 // get the value of the field                 const value = $labelElement.next().text().trim();                 // asign the key value into the reduced object                 // note that we used camelCase() to make the property easy to read                 fields[camelCase(key)] = value;                 // return the object                 return fields;             }, {})         );  }  async function main() {     const url = 'https://www.lseg.com/resources/1000-companies-inspire/2018-report-1000-companies-uk/search-1000-companies-uk-2018?results_per_page=100';     const companies = await scrape(url);      fs.writeFile('Output.txt', companies, (err) => {           if (err) throw err;          console.log('it/s done')     })      console.log(companies); }    main(); 
Download script demo [LINK] [Origin]
Download script demo [LINK 2] [Onedrive] Download script demo [LINK 2] [Google drive]