编码为 ascii 时引号丢失
Loss of quotes when encoding into ascii
我想从新闻文章中提取引文之间的文本。为此,第一步涉及提取新文章。然后在第二步中使用正则表达式来获取报价。我不确定,但是当我编码成 ascii 时引号丢失了。有解决办法吗?
from goose import Goose
from requests import get
response = get('http://www.nytimes.com/2015/05/19/health/study-finds-dense-breast-tissue-isnt-always-a-high-cancer-risk.html?src=me&ref=general')
extractor = Goose()
article = extractor.extract(raw_html=response.content)
text = article.cleaned_text
encode_text=text.encode('ascii','ignore')
comments=re.findall('"([^"]*)"', encode_text)
print comments
不要使用蛮力破坏所有内容,而是使用 Unidecode 将文本音译为 ASCII。
>>> unidecode.unidecode(u'“…”')
'"..."'
我想从新闻文章中提取引文之间的文本。为此,第一步涉及提取新文章。然后在第二步中使用正则表达式来获取报价。我不确定,但是当我编码成 ascii 时引号丢失了。有解决办法吗?
from goose import Goose
from requests import get
response = get('http://www.nytimes.com/2015/05/19/health/study-finds-dense-breast-tissue-isnt-always-a-high-cancer-risk.html?src=me&ref=general')
extractor = Goose()
article = extractor.extract(raw_html=response.content)
text = article.cleaned_text
encode_text=text.encode('ascii','ignore')
comments=re.findall('"([^"]*)"', encode_text)
print comments
不要使用蛮力破坏所有内容,而是使用 Unidecode 将文本音译为 ASCII。
>>> unidecode.unidecode(u'“…”')
'"..."'