gpt4 book ai didi

阿拉伯语的Python UTF8编码

转载 作者:行者123 更新时间:2023-12-05 05:28:07 25 4
gpt4 key购买 nike

我遇到编码问题,当我尝试抓取 youtube(阿拉伯语 channel )时:

#!/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

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

最佳答案

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

f"{yourString}".encode('latin-1').decode("utf-8")

关于阿拉伯语的Python UTF8编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14007121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com