我正在尝试使用python goose提取器从“纽约时报”上摘录文章。
我尝试过使用标准的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问题,无法从返回的原始数据中提取文章正文。我之前已经搜索过了,但是我找不到任何结果来解决我的问题。
发布于 2015-12-22 23:49:09
看起来goose在纽约时报上传统上有问题,因为(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 UTChttps://stackoverflow.com/questions/34419351
复制相似问题