question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add scrapeIt.fromStream function

See original GitHub issue

What do you think of a fromStream function which feeds the HTML parser chunk by chunk instead of allocating one big string in memory?

I have already implemented it and am using it in one of my projects: https://github.com/IonicaBizau/scrape-it/compare/master...ComFreek:master.

I also have a unit test at hand, which requires an upgrade of the package tester, as already mentioned at https://github.com/IonicaBizau/tester/issues/15.

t.it("scrape from stream", cb => {
    return t.expect(http.get(URL, response => {
        scrapeIt.fromStream(response, {
            title: "h1.title"
          , description: ".description"
          , date: {
                selector: ".date"
              , convert: x => new Date(x)
            }
        })
    })).resolves.toEqual({
        title: "Title"
      , description: "Lorem ipsum"
      , date: new Date("1988-01-01")
    })
})

Open points:

  • The normal scrapeIt method uses cheerio-req, which actually could benefit from the chunk by chunk loading as well.
  • Investigate how htmlparser2 deals with encodings.
  • [from a later comment] Wait for Cheerio adopting/discussing the Cheerio.load(dom) public API: https://github.com/cheeriojs/cheerio/issues/1126

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ComFreekcommented, Dec 23, 2017

My code only stores the DOM tree in memory, not the HTML string. I think the DOM is necessary for CSS-like selectors in scrape-it anyway.*

*) Actually, this exercise seems quite interesting: “Given a set of CSS selectors, does a program exist, which extracts the results from sequential HTML parsing?” or “Can we pre-compile a set of selectors, so that SAX-like parsing suffices to extract all the matches?”

0reactions
IonicaBizaucommented, Jan 1, 2020

I am going to close this, but contributions are welcome via PRs! 🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guarantee a Cheerio.load(dom) overload #1126 - GitHub
Add scrapeIt.fromStream function IonicaBizau/scrape-it#83 ... otherwise happy to add this as an additional method ( .stream or something)! ...
Read more >
Python webscraping: HTML instead of Javascript function
Here the values in the HTML body are missing and there is just the JavaScript script. How can i scrape this values? Thanks....
Read more >
Node.js Tips — Streams, Scraping, and Promisifying ...
Converting a Buffer into a ReadableStream in Node.js. We can convert a buffer to a readable stream with the ReadableStreamBuffer constructor.
Read more >
Scrape the Web with Node.js + Finding Undocumented APIs ...
This is an archive of a live stream that was broadcasted on twitch: https://www.twitch.tv/codinggarden/ Donate: ...
Read more >
How Web Scrape Multiple Pages with ONE Function with Python
Many websites use the same template for multiple pages of data, and this video shows you can create a single function to scrape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found