News for hackers. Stuff that matters.
Re:Web scraping with GPT-4o: powerful but expensive by parhamn on Monday September 02, 2024 @07:35PM (#41429690)
Is there a "html reducer" out there? I've been considering writing one. If you take a page's source it's going to be 90% garbage tokens -- random JS, ads, unnecessary properties, aggressive nesting for layout rendering, etc.

I feel like if you used a dom parser to walk and only keep nodes with text, the html structure and the necessary tag properties (class/id only maybe?) you'd have significant savings. Perhaps the xpath thing might work better too. You can even even drop necessary symbols and represent it as a indented text file.

We use readability for things like this but you lose the dom structure and their quality reduces with JS heavy websites and pages with actions like "continue reading" which expand the text.

Whats the gold standard for something like this?

Re:Web scraping with GPT-4o: powerful but expensive by axg11 on Monday September 02, 2024 @07:45PM (#41429746)
I wrote an in-house one for Ribbon. If there’s interest, will open source this. It’s amazing how much better our LLM outputs are with the reducer.
Re:Web scraping with GPT-4o: powerful but expensive by parhamn on Monday September 02, 2024 @07:48PM (#41429768)
Yes! Happy to try it on a fairly large user base and contribute to it! Email in bio if you want a beta user.
Re:Web scraping with GPT-4o: powerful but expensive by Tostino on Monday September 02, 2024 @07:47PM (#41429763)
I'm absolutely interested in this.
Re:Web scraping with GPT-4o: powerful but expensive by kurthr on Monday September 02, 2024 @07:46PM (#41429758)
That would be wonderful.
Re:Web scraping with GPT-4o: powerful but expensive by downWidOutaFite on Monday September 02, 2024 @08:37PM (#41430042)
+1
Re:Web scraping with GPT-4o: powerful but expensive by 7thpower on Monday September 02, 2024 @10:10PM (#41430573)
Yes please
Re:Web scraping with GPT-4o: powerful but expensive by ushtaritk421 on Tuesday September 03, 2024 @03:06AM (#41432110)
I would be very interested in this.
Re:Web scraping with GPT-4o: powerful but expensive by guwop on Tuesday September 03, 2024 @07:36AM (#41433839)
sounds amazing!
Re:Web scraping with GPT-4o: powerful but expensive by faefox on Tuesday September 03, 2024 @10:44AM (#41435456)
+1
Re:Web scraping with GPT-4o: powerful but expensive by chrisrickard on Tuesday September 03, 2024 @10:53AM (#41435546)
100%
Re:Web scraping with GPT-4o: powerful but expensive by yadaeno on Tuesday September 03, 2024 @11:10AM (#41435713)
+1
Re:Web scraping with GPT-4o: powerful but expensive by CalRobert on Tuesday September 03, 2024 @01:29PM (#41437142)
Add my voice to the chorus asking for this!
Re:Web scraping with GPT-4o: powerful but expensive by Opocio on Friday September 13, 2024 @02:49AM (#41528643)
+1
Re:Web scraping with GPT-4o: powerful but expensive by edublancas on Monday September 02, 2024 @07:42PM (#41429719)
author here: I'm working on a follow-up post. Turns out, removing all HTML tags works great and reduces the cost by a huge margin.
Re:Web scraping with GPT-4o: powerful but expensive by 7thpower on Monday September 02, 2024 @10:11PM (#41430581)
What do you mean? What do you use as reference points?
Re:Web scraping with GPT-4o: powerful but expensive by edublancas on Monday September 02, 2024 @11:07PM (#41430868)
nothing, I strip out all the HTML tags and pass raw text
Re:Web scraping with GPT-4o: powerful but expensive by isaacfung on Monday September 02, 2024 @11:45PM (#41431045)
How do you keep table structure?
Re:Web scraping with GPT-4o: powerful but expensive by jaimehrubiks on Tuesday September 03, 2024 @05:14AM (#41432905)
They should probably keep tables and lists and strip most of the rest.
Re:Web scraping with GPT-4o: powerful but expensive by AbstractH24 on Tuesday September 03, 2024 @07:00AM (#41433551)
Am I crazy or is there no way to “subscribe” to your site? Interested to follow your learnings in this area.
Re:Web scraping with GPT-4o: powerful but expensive by edublancas on Tuesday September 03, 2024 @02:32PM (#41437703)
there isn't. but you can connect X or LinkedIn.

I might add a subscribe button once I get some time :)

Re:Web scraping with GPT-4o: powerful but expensive by ErikAugust on Monday September 02, 2024 @07:39PM (#41429712)
Running it through Readability:

https://github.com/mozilla/readability

Re:Web scraping with GPT-4o: powerful but expensive by parhamn on Monday September 02, 2024 @07:44PM (#41429738)
I snuck in an edit about readability before I saw your reply. The quality of that one in particular is very meh, especially for most new sites and then you lose all of the dom structure in case you want to do more with the page. Though now I'm curious how it works on the weather.com page the author tried. pupeteer -> screenshot -> ocr (or even multi-modal which many do OCR first) -> LLM pipeline might work better there.
Re:Web scraping with GPT-4o: powerful but expensive by LunaSea on Tuesday September 03, 2024 @03:21AM (#41432210)
Issue is that Llama are x100 more expensive at the very least.
Re:Web scraping with GPT-4o: powerful but expensive by lelandfe on Monday September 02, 2024 @07:41PM (#41429716)
Only works insofar as sites are being nice. A lot of sites do things like: render all text via JS, render article text via API, paywall content by showing a preview snippet of static text before swapping it for the full text (which lives in a different element), lazyload images, lazyload text, etc etc.

DOM parsing wasn't enough for Google's SEO algo, either. I'll even see Safari's "reader mode" fail utterly on site after site for some of these reasons. I tend to have to scroll the entire page before running it.

Re:Web scraping with GPT-4o: powerful but expensive by zexodus on Tuesday September 03, 2024 @03:47AM (#41432365)
It's possible to capture the DOM by running a headless browser (i.e. with chromedriver/geckodriver), allowing the js execute and then saving the HTML.

If these readers do not use already rendered HTML to parse the information on the screen, then...

Re:Web scraping with GPT-4o: powerful but expensive by lelandfe on Tuesday September 03, 2024 @09:26AM (#41434730)
Indeed, Safari's reader already upgrades to using the rendered page, but even it fails on more esoteric pages using e.g. lazy loaded content (i.e. you haven't scrolled to it yet for it to load); or (god forbid) virtualized scrolling pages, which offloads content out of view.

It's a big web out there, there's even more heinous stuff. Even identifying what the main content is can be a challenge.

And reader mode has the benefit of being ran by the user. Identifying when to run a page-simplifying action on some headlessly loaded URL can be tricky. I imagine it would need to be like: load URL, await load event, scroll to bottom of page, wait for the network to be idle (and possibly for long tasks/animations to finish, too)

[dead]
Re:Web scraping with GPT-4o: powerful but expensive by BeetleB on Tuesday September 03, 2024 @11:20AM (#41435827)
+1 for this. I too use Readability via Simon's shot-scraper tool.
Re:Web scraping with GPT-4o: powerful but expensive by purple-leafy on Monday September 02, 2024 @09:55PM (#41430481)
I wrote one for a project that captures a portion of the DOM and sends it to an LLM.

It’s strips all JS/event handlers, most attributes and most CSS, and only keeps important text nodes

I needed this because I was using LLM to reimplement portions of a page using just tailwind, so needed to minimise input tokens

Re:Web scraping with GPT-4o: powerful but expensive by suchintan on Tuesday September 03, 2024 @12:38AM (#41431309)
We wrote something like this to power Skyvern: https://github.com/Skyvern-AI/skyvern/blob/0d39e62df6c516e0a...

It's adapted from vimium and works like a charm. Distill the html down to it's important bits, and handle a ton of edge cases along the way haha

Re:Web scraping with GPT-4o: powerful but expensive by nickpsecurity on Tuesday September 03, 2024 @11:58AM (#41436210)
That’s easy to do with BeautifulSoup in Python. Look up tutorials on that. Use it on non-essential tags. That will at least work when the content is in HTML rather than procedurally generated (eg JavaScript).