-2

I'm creating a React Web Application and using request and cheerio to do some Web Scraping. I need to extract data from a .html file. The user enters with a .html in an input:

<input type='file' />

How can I extract data from the file? It is possible with those libraries? I know that request needs an url and I guess that it will be the local path to file. I used the following code to do Web Scraping:

const foo = await new Promise(function (resolve, reject) {
    request.get(url, (err, res2, data) => {
        const $ = cheerio.load(data)
        let s = $("tbody < table.table_lt").text().replace(/\t/g, '').replace(/\n/g, '')
        resolve(s)
    })  
})

But this work just with Web.

  • You're using wrong tags on your question. This is not a question related to `node.js`. Try to understand how to ask: https://stackoverflow.com/questions/ask – Akansh Aug 14 '19 at 11:00

1 Answers1

0

As answered here: https://stackoverflow.com/a/31104553

In Node.js, you can use Path's parse module...

var path = require('path');
var file = '/home/user/dir/file.txt';

var filename = path.parse(file).base;
//=> 'file.txt'
alainazpe
  • 1
  • 1