from bs4 import BeautifulSoup
from langdetect import detect
with open("foo.html", "rb") as f:
soup = BeautifulSoup(f, "lxml")
[s.decompose() for s in soup("script")] # remove <script> elements
body_text = soup.body.get_text()
print(detect(body_text))
您可以提取内容块,然后使用一些python语言检测,如langdetect或{a2}。在
下面是一个简单的示例,演示如何使用BeautifulSoup提取HTML正文文本,langdetect用于语言检测:
也许你有这样一个标题:
如果是这种情况,您可以用lang=“fr”看到这是一个法语网页。如果不是这样的话,猜测一篇文章的语言并不是件小事。在
相关问题 更多 >
编程相关推荐