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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top