OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to use cheerio from a browser

  • Thread starter Thread starter Chenming Zhang
  • Start date Start date
C

Chenming Zhang

Guest
I am new to JavaScript and am pretty sure I am missing something fundamental in using JSfrom a HTML page (to be browsed by a web browser).

My goal is to scrap photo links from a dynamic website using cheerio and display them in a js gadget (e.g., using lightslider), it looks quite successful following this tutorial to obtain the following script and run it by simply nodejs scrapt.js in a bash terminal:

Code:
var request = require('request');
var cheerio = require('cheerio');
request('https://outbox.eait.uq.edu.au/uqczhan2/Photos/', function (error, respo
  if (!error && response.statusCode == 200) {
    console.log(html);
  }
});

But now I am not able to run this script in a general webbrowser (by pressing f12 -> console), as error shows after the first syntax:

Code:
>var request = require('request');
VM85:1 Uncaught ReferenceError: require is not defined
    at <anonymous>:1:15

I understood some JavaScript modules is required to be loaded before using them, for example for d3.js. i need to run:

Code:
<script src="https://d3js.org/d3.v4.min.js"></script>

to use all the d3 function. how should I achieve the same thing that would allow me to use cheerio in a web browser?

<p>I am new to JavaScript and am pretty sure I am missing something fundamental in using JSfrom a HTML page (to be browsed by a web browser). </p>

<p>My goal is to scrap photo links from <a href="https://outbox.eait.uq.edu.au/uqczhan2/Photos/" rel="noreferrer">a dynamic website</a> using cheerio and display them in a js gadget (e.g., using <a href="http://sachinchoolur.github.io/lightslider/" rel="noreferrer">lightslider</a>), it looks quite successful <a href="https://www.digitalocean.com/commun...est-and-cheerio-to-set-up-simple-web-scraping" rel="noreferrer">following this tutorial</a> to obtain the following script and run it by simply <strong>nodejs scrapt.js</strong> in a bash terminal:</p>

<pre><code>var request = require('request');
var cheerio = require('cheerio');
request('https://outbox.eait.uq.edu.au/uqczhan2/Photos/', function (error, respo
if (!error && response.statusCode == 200) {
console.log(html);
}
});
</code></pre>

<p>But now I am not able to run this script in a general webbrowser (by pressing f12 -> console), as error shows after the first syntax:</p>

<pre><code>>var request = require('request');
VM85:1 Uncaught ReferenceError: require is not defined
at <anonymous>:1:15
</code></pre>

<p>I understood some JavaScript modules is required to be loaded before using them, for example for d3.js. i need to run:</p>

<pre><code><script src="https://d3js.org/d3.v4.min.js"></script>
</code></pre>

<p>to use all the d3 function. how should I achieve the same thing that would allow me to use cheerio in a web browser?</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top