-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?

Irmantas Želionis
  • 2,194
  • 3
  • 17
  • 30

1 Answers1

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

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321