1

我正在尝试使用 python goose extractor 从纽约时报中提取文章。

我尝试使用标准的 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 goose 问题,无法从返回的原始数据中提取文章正文。我之前搜索过,但找不到任何可以解决我的问题的结果。

4

1 回答 1

1

看起来这只鹅在《纽约时报》上一直存在问题,因为(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
于 2015-12-22T15:49:09.310 回答