GithubHelp home page GithubHelp logo

Comments (6)

allison-truhlar avatar allison-truhlar commented on May 27, 2024 3

@user4302 I encountered this same issue with .fromURL. I think it is because this function is not yet available in the published npm package for Cheerio. The top of the website mentions "Cheerio's website is still a work-in-progress, and covers Cheerio's next release that isn't available yet." If you look in the Github Cheerio repository, you can find the function .from URL in cheerio/src/batteries. However, in the npm package, this path does not exist.

Using this code achieved the same goal as using fromURL for me:

const response = await axios.get(url);
const html = response.data;

// Use Cheerio to parse the HTML
const $ = cheerio.load(html);

from cheerio.

loganknecht avatar loganknecht commented on May 27, 2024

I am experiencing this issue as well, except it occurs when I call replaceWith

from cheerio.

loganknecht avatar loganknecht commented on May 27, 2024

Please disregard. The solution to this was.

const cheerio = require("cheerio");
// ...
const cheerio_file_dom = cheerio.load(current_file_contents);
// ...
const script_elements = cheerio_file_dom("script[src$=.js]");
script_elements.each((index, current_script_elements) => {
    const original_src_value = current_script_elements.attribs["src"];
    const new_value = `{{ require_js(get_asset_url(".${original_src_value}")) }}`;

    cheerio_file_dom(current_script_elements).replaceWith(new_value);
});

I think @user4302 may be incorrectly referencing the wrong object for the .fromURL command as well.

from cheerio.

user4302 avatar user4302 commented on May 27, 2024

Please disregard. The solution to this was.

const cheerio = require("cheerio");
// ...
const cheerio_file_dom = cheerio.load(current_file_contents);
// ...
const script_elements = cheerio_file_dom("script[src$=.js]");
script_elements.each((index, current_script_elements) => {
    const original_src_value = current_script_elements.attribs["src"];
    const new_value = `{{ require_js(get_asset_url(".${original_src_value}")) }}`;

    cheerio_file_dom(current_script_elements).replaceWith(new_value);
});

I think @user4302 may be incorrectly referencing the wrong object for the .fromURL command as well.

i was following this guide in the docs
https://cheerio.js.org/docs/api#fromurl
i just saw that i used data instead of $ when assigning the variable
if i used $ would it have worked?

from cheerio.

sonyarianto avatar sonyarianto commented on May 27, 2024

Hmm I got into this trap as well hehe. The .fromURL() it's not there anymore :)

from cheerio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.