我正在嘗試在 instagram 中抓取文本并檢查是否可以在 bio 中找到一些關鍵字,但用戶使用特殊字體,因此我無法識別特定單詞,如何洗掉文本的字體或格式以便我可以搜索單詞?
import re
test="???????????? ?????? ???????????? ???????? ???????????? ?????? ????????. "
x = re.findall(re.compile('past'), test)
if x:
print("TEXT FOUND")
else:
print("TEXT NOT FOUND")
未找到文字
另一個例子:
import re
test="????????? ??????? ??s?????"
test=test.lower()
x = re.findall(re.compile('graphic'), test)
if x:
print("TEXT FOUND")
else:
print("TEXT NOT FOUND")
未找到文字
uj5u.com熱心網友回復:
您可以使用unicodedata.normalize來回傳 Unicode 字串的正常形式。對于您的示例,請參見以下代碼片段:
import re
import unicodedata
test="???????????? ?????? ???????????? ???????? ???????????? ?????? ????????. "
formatted_test = unicodedata.normalize('NFKD', test).encode('ascii', 'ignore').decode('utf-8')
x = re.findall(re.compile('past'), formatted_test)
if x:
print("TEXT FOUND")
else:
print("TEXT NOT FOUND")
輸出將是:
找到文本
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426935.html
標籤:Python python-3.x 网页抓取 回覆 python-unicode
上一篇:我無法列印用硒報廢的資料
