0

I've read lots of messages around here for this problem, but I couldn't solve it for my particular case. I save a html page in Firefox (the page is one of my Youtube playlist). But I get the error from beautifulsoup:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1000858: character maps to

playlist = BeautifulSoup(html_file, 'lxml', from_encoding="utf-8")

I tried several encoding parameters with no success. Html file can be downloaded here: https://www.filehosting.org/file/details/879011/playlist.html

If anyone can help...

3
  • Can you show more code or the web page? Commented Jun 30, 2020 at 14:46
  • can you explain why you're encoding Commented Jun 30, 2020 at 14:47
  • The htlm page can be downloaded as mentioned. I first tried without the from_encoding argument, but it didn't work. The only code is: with open(playlist_file) as html_file: playlist = BeautifulSoup(html_file, 'lxml', from_encoding="utf-8") Commented Jun 30, 2020 at 15:47

2 Answers 2

3

Well, after hours spent on browsing everywhere to find a solution, it was really simple actually: just ignoring the errors have produced the right output as you got! Simply with:

with open('playlist.html', 'r', encoding='utf-8', errors='ignore') as f_in:
soup = BeautifulSoup(f_in.read(), 'html.parser')

Thank you for your help!

PS: I'm just wondering if the errors weren't caused by lots of graphical characters due to special fonts used (little drawings next to the titles)...

Sign up to request clarification or add additional context in comments.

1 Comment

Always feels weird when I have to tell my computer "just ignore the error, it's fine" but damned if it doesn't work in this case.
1

I downloaded your file from the filehosting, and from_encoding="utf-8" is not needed - it produces warning if it's there.

from bs4 import BeautifulSoup

with open('playlist.html', 'r') as f_in:
    soup = BeautifulSoup(f_in.read(), 'html.parser')

    for title in soup.select('#video-title'):
        print(title.get_text(strip=True))

Prints:

Gordon Ramsay Cooks Carbonara in Under 10 Minutes | Ramsay in 10
Sans four, frais et doux en quelques minutes # 303
Comment faire des tomates séchées au soleil - Les Sourciers
Italian homemade sun dried tomatoes
Recette du clafoutis moelleux aux cerises - 750g
Recette des Carrés Framboise Pistache
Une QUICHE ensoleillée et végétarienne pour un repas facile à faire !
Millionaires Shortbread Recipe - Layers of WIN! | Cupcake Jemma
Rum Raisin Ice Cream Recipe Demonstration - Joyofbaking.com
🍋 ENTREMETS CITRON PRALINÉ 🍋
Recette de Tarte aux Fruits
Anna Bakes DECADENT Chocolate Whoopie Pies!
Ultimate Lemon Meringue Layer Cake | Cupcake Jemma
Blueberry Pie Recipe Demonstration - Joyofbaking.com
The Macaron is dead! Long live the Macaroon! | Cupcake Jemma
Anna Makes AMAZING Raspberry Jelly Donuts!
Des SANDWICHS originaux et surtout à dévorer avec les doigts !
Astuce de boulanger   comment préparer une baguette tradition maison Gontran cherrier
Recette des Tartelettes Citron Chocolat Blanc Estragon de Frédéric Bau
Cream Cheese Cookies
🌰  GANACHE AU PRALINÉ 🌰
Anna Bakes INCREDIBLE Fudge Brownies LIVE!
Triple Chocolate Brownies Recipe Demonstration - Joyofbaking.com
Make your own Piping Bag! Quick & Easy DIY Piping Bag Tip | Cupcake Jemma
Professional Baker's Best Checkerboard Cookie Recipe!
Anna Bakes an AMAZING Mango Mousse Tart!
Un LAYER CAKE AUX FRAISES expliqués pas à pas pour une parfaite réussite !
🔥 CHOUQUETTES FACILE ET INRATABLES 🔥
Recette des Petites Tropéziennes Fraise Vanille
Anna Bakes CLASSIC Florentine Cookies!
Classic Carrot Cake Recipe | Cupcake Jemma
Anna Teaches You How To Make PIE DOUGH LIVE | Oh Yum 101
🌰 TARTE PRALINOISE (CHOCOLAT PRALINÉ) FACILE 🌰
🐿 SALAMBO MAISON (ou GLAND) 🐿
Tuto Recette : La Tarte Alsacienne aux Cerises ! 🍒
Recette de Brookies
Anna Bakes OUTSTANDING Pfeffernusse Cookies!
Une recette accessible aux enfants avec seulement 1 courgette, 2 tomates et 3 œufs| Savoureux.tv
Biscuits Recipe Demonstration - Joyofbaking.com
🍓 TARTE AUX FRAISES TRADITIONNELLE et FACILE 🍓
Anna Bakes AMAZING Crispy Lavash Bread!
Tuto Recette Facile : la Focaccia
👱‍♀ CHEESECAKE PISTACHE FRAMBOISE SPÉCIAL FÊTE DES MÈRES 👱‍♀
Recette de Cake Salé aux Pruneaux, Lardons et Fromage
Anna Bakes OUTSTANDING Blood Orange Syrup Cake!
Professional Baker's Best Rhubarb Crumble Tart Recipe!
Double Rainbow Cupcakes! | Bake with Sally | Cupcake Jemma
🌞 LES MONTECAOS ! 2 RECETTES FACILES ET RAPIDES 🌞
Petit déjeuner pour les paresseux - je mets tout dans une casserole et sur la cuisinière
Raspberry White Chocolate New York Cookie Bake Along! | with Jemma, Sally & Dane
Recette de Choux Pralinés façon Paris-Brest
🍓 GÂTEAU ROULÉ AUX FRAISES 🍓
Tuto Recette Facile : le Cake Chocolat et Gianduja
Réalisez ces délicieux carrés au chocolat, crémeux et moelleux. Ils sont SUPER!| Savoureux.tv
Recette des Rochers Noix de Coco Framboise Chocolat Blanc
🥖 PAIN MAGIQUE SANS PÉTRISSAGE, FACILE ET RAPIDE (et ultra bon) ! 🥖
Recette Spéciale CAP : la Charlotte Poire Chocolat !
🌰 BISCUITS SABLÉS AU NUTELLA 🌰
Tuto Recette : le Banoffee, c'est facile !
Recette des Pains ou Buns Farcis au Poulet, Légumes et Épices
Butter Fingers - Les Petits Croissants aux Amandes et aux Pignons de Pin
RECETTE PETITS CROISSANTS AMANDE PIGNONS FLEUR D'ORANGER
Le Succès Praliné : la recette facile expliquée de A à Z !
Recette des Sablés au Sarrasin, Graines et Perles au Chocolat de Frédéric Bau
Professional Baker's Best Pretzel Recipe!
Recette du Gâteau Napolitain maison
Recette du Paris-Brest
Recette de gâteau au chocolat simple et délicieuse. Mélangez le tout et goûtez le!| Savoureux.tv
Recette du Milkshake à la fraise - 750g
Très simple et fait en seulement 2 minutes.| Savoureux.tv
Recette de la Tarte Tropézienne
💕 PASTEIS DE NATA (FLANS PORTUGAIS) à LISBONNE ! 💕
Recette de Cupcakes à la Vanille Cœur Praliné
Super Easy, Ridiculously Tasty Lamingtons Recipe! | Bake at Home | Cupcake Jemma
Recette de Verrines Fraise Citron
Biscuits salés faits maison - ils sont parfaits pour le panier-repas !| Savoureux.tv
🍓 CHARLOTTE AUX FRAISES FACILE (tuerie !) 🍓
Coffee cake ou Gâteau pour le café - 750g
Crème Caramel
Ceci est une nouvelle recette. Un gâteau d'exception!| Savoureux.tv
BEIGNETS au FOUR sans friture : + légers et moelleux 😜
Cake aux pommes facile et rapide - 750g
Recette de Gâteau aux pommes et au yaourt - 750g
Italian Grandma Makes Gnocchi
Tuto Recette : les Pizzas Faciles !
🥐 RECETTE DES CROISSANTS MAISON 🥐
Muffins au fromage - ils sont si savoureux et moelleux qu’ils fondent dans la bouche! | Savoureux.TV
Professional Baker's Best Double Chocolate Trifle Recipe!
Professional Baker's Best Chocolate Torte Recipe!
How to Make Perfect Caramel Popcorn | Cupcake Jemma
Double Choc Chip NYC Cookies | Super Gooey Chocolate New York Cookie Recipe | Cupcake Jemma
Red Velvet New York Cookie Recipe! | Cupcake Jemma
Recette des Petites Baguettes de Pain Maison
Recette du sunday et ses 4 accompagnements GOURMANDS - 750g
🐯 TIGRÉS AU NUTELLA, RECETTE FACILE ET RAPIDE 🐯
BAKE AT HOME | Jamaican Ginger Loaf Cake | Cupcake Jemma
4 recettes étonnantes et gourmandes avec des fraises - 750g
⚓ FAR BRETON NATURE - FACILE ET RAPIDE ⚓
Recette Spéciale CAP : la Pâte Feuilletée, le Millefeuille et les Chaussons a
Homemade Mac & Cheese with Cauliflower | Keep Cooking & Carry On | Jamie Oliver  #withme

4 Comments

With your code I get the same error... I created a new python file with your code only and same issue. How the hell did you get the print output!?
I'm guessing it's your IDE that's causing the error. Try writing to a file instead of printing.
@jackgames I see you are using windows and use default encoding cp1252. Change default encoding to utf-8, for example from here stackoverflow.com/questions/2276200/…
Until now, I've tried several solutions given in the mentioned article (very tough problem) with still no success... P.S: I'm using Python 3.7.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.