Как бы я не вставлял эту строчку - всегда вываливается ошибка
str.decode('cp1251').encode('utf8')
AttributeError: type object 'str' has no attribute 'decode'
Пожалуйста подскажите как ее нужно правильно вписать:
import requests
from lxml import html
#r = requests.get('lenta.ru')
r = requests.get('da.ru')
docHtml = r.text
parsed_body = html.fromstring(docHtml)
for y in parsed_body.xpath("//a"):
url=y.get("href")
anchor=y.text
print(anchor) #показываем кракозяблы
encoded = str.encode(anchor, 'utf-8') # перекодируем
print(encoded) #показываем более другие кракозяблы
str.decode('cp1251').encode('utf8')
AttributeError: type object 'str' has no attribute 'decode'
Пожалуйста подскажите как ее нужно правильно вписать:
import requests
from lxml import html
#r = requests.get('lenta.ru')
r = requests.get('da.ru')
docHtml = r.text
parsed_body = html.fromstring(docHtml)
for y in parsed_body.xpath("//a"):
url=y.get("href")
anchor=y.text
print(anchor) #показываем кракозяблы
encoded = str.encode(anchor, 'utf-8') # перекодируем
print(encoded) #показываем более другие кракозяблы