Comments (6)
@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.
I am experiencing this issue as well, except it occurs when I call replaceWith
from cheerio.
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.
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.
Hmm I got into this trap as well hehe. The .fromURL() it's not there anymore :)
from cheerio.
Related Issues (20)
- Could I select a custom tag like <aaa></aaa>?
- How to avoid cheerio to escape character when i use `.html()` function HOT 2
- $.extract is not a function HOT 2
- `$.attr('value')` returns incorrect result for an `<option>` without a value attribute
- Can't set existing attribute as undefined HOT 1
- Custom self closing label parsing error, resulting in incorrect document structure
- Can't start telegram bot HOT 3
- issue with custom tags defined in head HOT 2
- Incorrect code example in intro documation
- Multiple html tags are deleted HOT 2
- How to "replaceWith" on plain text, which is not a DOM Elements? HOT 5
- Unsafe legacy renegotiation disabled
- text() method merges text parts HOT 3
- Bug: Crawler reached the maxRequestsPerCrawl limit of 1 requests and will shut down soon HOT 1
- Bug: XML tags with mixed case, when using lowerCaseTags: true, selectors will be lowercased before comparing with the xml tag name
- exporting function from battiers
- Error with nextjs 14 HOT 1
- Cherrio is unable to retrieve content with property of og in the meta tag HOT 3
- If the page is SPA (such as Vue), can't I use Cheerio to retrieve the content of the website that has been fully loaded HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cheerio.