2016-05-17 3 views
-1

私はPython Gooseを使ってWebページから記事を抽出しています。多くの言語でうまく動作しますが、ヒンディー語では失敗します。私はstopwords-hi.txtとしてヒンディー語の停止を加え、target_languageをhiに設定しようとしましたが、成功しませんでした。 ありがとう、Eranガチョウでヒンディー語のWebページから記事を抽出するには?

+0

どのように正確に失敗するのですか? –

+0

cleaned_text関数は何も返しません –

答えて

0

ええ、同じ問題がありました。私はインドのすべての地域の言語で記事を抽出していましたが、Gooseでコンテンツを単独で抽出することはできませんでした。 記事の説明だけで作業できる場合、meta_descriptionは完全に機能します。あなたは何も返さないcleaned_textの代わりにそれを使うことができます。

別の方法が、コードの複数行:

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) 

オープン開示:私は実際には、スタックオーバーフローのどこかに元のコードを得ました。それを少し変更しました。

関連する問題