我使用Python Goose从网页中提取文章。它适用于许多语言,但对印地语不适用。我试图将Hindi stop添加为stopwords-hi.txt并将target_language设置为hi,但没有成功。 谢谢,伊兰
答案 0 :(得分:0)
另一种选择,但更多代码行:
import urllib
from bs4 import BeautifulSoup
url = "http://www.jagran.com/news/national-this-pay-scale-calculator-will-tell-your-new-salary-after-7th-pay-commission-14132357.html"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html, "lxml")
##removing all script, style and reference links to get only the article content
for script in soup(["script", "style",'a',"href","formfield"]):
script.extract()
text = soup.get_text()
lines = (line.strip() for line in text.splitlines())
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
text = '\n'.join(chunk for chunk in chunks if chunk)
print (text)
公开披露:我实际上只在堆栈溢出的某处获得了原始代码。修改了一下。