如何提取文章蟒蛇鹅与纽约时报



我正试图使用python鹅提取器从《纽约时报》中提取文章。

我尝试过使用标准的url检索方式:

g.extract(url=url)

然而,这会产生一个空字符串。因此,我尝试了通过文档推荐的以下方式:

import urllib2
import goose
url = "http://www.nytimes.com/reuters/2015/12/21/world/africa/21reuters-kenya-attacks-somalia.html?_r=0"
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
response = opener.open(url)
raw_html = response.read()
g = goose.Goose()
a = g.extract(raw_html=raw_html)
a.cleaned_text

再次为"cleaned_text"返回一个空字符串。html是从网站上检索到的。我也尝试过使用请求,但结果相同。

我认为这是一个python鹅问题,因为无法从返回的原始数据中提取文章正文。我之前搜索过,但找不到任何解决我问题的结果。

《纽约时报》似乎传统上一直存在问题,因为(1)他们通过另一个页面重定向用户以添加/检查cookie(请参阅下面的curl),以及(2)他们实际上没有在页面加载中加载文章的文本。他们在第一次执行广告显示代码后异步执行。

~ curl -I "http://www.nytimes.com/reuters/2015/12/21/world/africa/21reuters-kenya-attacks-somalia.html"
HTTP/1.1 303 See Other
Server: Varnish
Location: http://www.nytimes.com/glogin?URI=http%3A%2F%2Fwww.nytimes.com%2Freuters%2F2015%2F12%2F21%2Fworld%2Fafrica%2F21reuters-kenya-attacks-somalia.html%3F_r%3D0
Accept-Ranges: bytes
Date: Tue, 22 Dec 2015 15:46:55 GMT
X-Varnish: 1338962331
Age: 0
Via: 1.1 varnish
X-API-Version: 5-0
X-PageType: article
Connection: close
X-Frame-Options: DENY
Set-Cookie: RMID=007f01017a275679706f0004;Path=/; Domain=.nytimes.com;Expires=Wed, 21 Dec 2016 15:46:55 UTC

最新更新