Frage

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?

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top