3

我有一个编码问题,当我尝试抓取 youtube(阿拉伯语频道)时:

#!/usr/bin/python
# -*- coding: utf8 -*- 
from django.core.management.base import BaseCommand, CommandError
import requests, lxml, re
from lxml import html

class Command(BaseCommand):
    def handle(self, *args, **options):
        r = requests.get("https://www.youtube.com/user/aljazeerachannel/videos?view=0")
        root = lxml.html.fromstring(r.content)

        for data in root.xpath('.//*[@id="branded-page-body"]/div/div/div[1]/div/div[2]/ul/li[1]/span/span/a'):
            print data.text

结果是:

[root@vmi9105 buzzbal]# python manage.py youtube

        اÙتخابات اÙÙجاÙس اÙبÙدÙØ© Ù٠سÙØ·ÙØ© عÙÙاÙ
4

1 回答 1

2

试试这个它解决了我在 python 中的问题:

f"{yourString}".encode('latin-1').decode("utf-8")
于 2021-07-30T19:49:50.830 回答