문제

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