1

Im getting error:

File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u0106' in position 73: character maps to

This is my code:

import requests from bs4 import BeautifulSoup url = 'http://www.privredni-imenik.com/firma/68225-a_expo' r = requests.get(url) soup = BeautifulSoup(r.content, "html.parser") g_data = soup.find_all("div", {"class":"podaci"}) print(g_data) 

How can i encode data in utf-8. i have tried solutions from other topics, but none of them work for me.

4
  • 1
    do you have # -*- coding: utf-8 -*- at the begging of your file? Commented Jul 17, 2015 at 21:30
  • Didnt have, i have just added it and its the same. Commented Jul 17, 2015 at 21:35
  • 1
    try g_data.decode('utf_8') Commented Jul 17, 2015 at 21:45
  • AttributeError: 'ResultSet' object has no attribute 'decode' Commented Jul 17, 2015 at 23:31

1 Answer 1

2
import requests from bs4 import BeautifulSoup url = 'http://www.privredni-imenik.com/firma/68225-a_expo' r = requests.get(url) soup = BeautifulSoup(r.content, "html.parser") g_data = soup.find_all("div", {"class":"podaci"}) for i in g_data: some = i.text.encode('utf-8', 'replace') print (some) 

It works, im receiving data but with weird characters.. Well thats question for another topic :)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.