TypeError: дескриптор «split» требует объекта «str», но получил «байты»Python

Программы на Python
Anonymous
TypeError: дескриптор «split» требует объекта «str», но получил «байты»

Сообщение Anonymous »

Я пытаюсь получить данные из ESPN Cricinfo, используя скрипт Python, доступный на Github. Код следующий.

Код: Выделить всё

import urllib.request as ur
import csv
import sys
import time
import os
import unicodedata
from urllib.parse import urlparse
from bs4 import BeautifulSoup

BASE_URL = 'http://www.espncricinfo.com'
for i in range(0, 6019):
url = 'http://search.espncricinfo.com/ci/content/match/search.html?search=first%20class;all=1;page='
soupy = BeautifulSoup(ur.urlopen(url + str(i)).read())

time.sleep(1)
for new_host in soupy.findAll('a', {'class' : 'srchPlyrNmTxt'}):
try:
new_host = new_host['href']
except:
continue
odiurl = BASE_URL + urlparse(new_host).geturl()
new_host = unicodedata.normalize('NFKD', new_host).encode('ascii','ignore')
print (new_host)
print (str.split(new_host, "/"))[4]
html = urllib2.urlopen(odiurl).read()
if html:
with open('espncricinfo-fc/{0!s}'.format(str.split(new_host, "/")[4]), "wb") as f:
f.write(html)
И ошибка именно в этой строке.

Код: Выделить всё

print (str.split(new_host, "/"))[4]
Ошибка типа: дескриптор «split» требует объекта «str», но получил «байты».
Любая ваша помощь будет оценена по достоинству. Спасибо

Подробнее здесь: https://stackoverflow.com/questions/674 ... ed-a-bytes

Вернуться в «Python»