Live data from Hacker News

Beautiful Soup

crummy.com

11–20 of 95 posts

Re: Beautiful Soup

#11

How helpful is this when you're dealing with a website that does not degrade gracefully and insists using JavaScript to shove things in where a static webpage would work? (For example, scraping football scores from NFL.com)

its not useful in those cases, but usually for those js rendered sites you can replicate the ajax requests which happen and get nicely formed json documents to parse through instead.

Re: Beautiful Soup

#12

How helpful is this when you're dealing with a website that does not degrade gracefully and insists using JavaScript to shove things in where a static webpage would work? (For example, scraping football scores from NFL.com)

Easiest in that case is probably to use something like headless chrome. But that is also significantly more demanding in terms of resources.

Re: Beautiful Soup

#13

How helpful is this when you're dealing with a website that does not degrade gracefully and insists using JavaScript to shove things in where a static webpage would work? (For example, scraping football scores from NFL.com)

In those cases you might want to check out SeleniumBase: https://seleniumbase.io/

Re: Beautiful Soup

#14

Great memories with this library, one of my all time favs. It is fast? no. But it had a fantastic mission: extracting data from malformed HTML. Might be less common now but back then (~10+ years ago) it was still rampant. Many if not most parsers would barf on any deviation from the standard, leaving you to hand-roll regex solutions and ugly corner cases. BS covered a LOT of these cases without forcing you to write t…

absolutely. i wrote this mobile allergy data thing and getting the data was mostly scraping from news websites that did terrible things with javascript to keep scrapers and ad blockers out. Beautiful Soup worked past all of that easily. Probably my favorite Python library.

Re: Beautiful Soup

#15

How helpful is this when you're dealing with a website that does not degrade gracefully and insists using JavaScript to shove things in where a static webpage would work? (For example, scraping football scores from NFL.com)

[deleted]

Re: Beautiful Soup

#16
Is Beautiful Soup still the best way to scrape the web with python?

IIRC, Beautiful Soup doesn't handle javascript, so at least for JS you're forced to use something else.

I'm also looking forward to seeing how people scrape the web once Web Assembly becomes prevalent.

Re: Beautiful Soup

#17
Years ago, I got the privilege of working at the same company with the author, Leonard Richardson. Really nice guy, super nerd and hilariously funny.

Re: Beautiful Soup

#18

Is Beautiful Soup still the best way to scrape the web with python? IIRC, Beautiful Soup doesn't handle javascript, so at least for JS you're forced to use something else. I'm also looking forward to seeing how people scrape the web once Web Assembly becomes prevalent.

It can be useful if it fits your case, the more recent scrapers run a whole browser with automation which can make scraping stuff a lot easier, since js will run etc

Re: Beautiful Soup

#19
post #11

How helpful is this when you're dealing with a website that does not degrade gracefully and insists using JavaScript to shove things in where a static webpage would work? (For example, scraping football scores from NFL.com)

its not useful in those cases, but usually for those js rendered sites you can replicate the ajax requests which happen and get nicely formed json documents to parse through instead.

Or the data is stored in js objects within script tags in the html and can be extracted programmatically. It's getting common with SSG sites using SPA frameworks.

For example, the new Google Play Store website stores the data in AF_initDataCallback calls and can be extracted with re.findall(r"AF_initDataCallback\((.*?)\);", html_string).

Re: Beautiful Soup

#20
I used this recently to scrape a bunch of online restaurant reviews by a guy who I really like, use regex to get the postcode from the markup, do a geocode using postcodes.io, then plot the reviews on a Google map. It took about two / three hours and felt kinda dirty in a good way. Beautiful Soup made the first part really easy.
Post reply on HN