-2

I am trying to get Premier league table with this code:

from bs4 import BeautifulSoup import requests url ="http://www.premierleague.com/en-gb.html" r = requests.get(url) soup = BeautifulSoup(r.content) table = soup.find('table', {'class': 'leagueTable'}) rows = table.findAll('tr') data = [[td.text for td in tr.findAll("td")] for tr in rows] for i in data: print i 

Everything works perfect, except I get results in unicode. How to convert it into plain text?

2
  • 1
    Is this helpful? stackoverflow.com/questions/1207457/… Commented May 10, 2014 at 8:25
  • You can encode your Unicode stings. But why do yo want it? Commented May 10, 2014 at 8:35

1 Answer 1

1

You can change the line to text.encode("utf-8"):

data = [[td.text.encode("utf-8") for td in tr.findAll("td")] for tr in rows] or str(td.text) 

Lots of info in the BeautifulSoup docs

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.