首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从卫报API获取文章文本

从卫报API获取文章文本
EN

Stack Overflow用户
提问于 2015-12-05 16:44:34
回答 2查看 4.1K关注 0票数 3

我在从“卫报”获得新闻API的文章文本时遇到了问题。我有一个url,它是这样的:http://content.guardianapis.com/search?section=technology&api-key=MYKEY和我得到的响应如下:

代码语言:javascript
复制
{
"response": {
    "status": "ok",
    "userTier": "developer",
    "total": 54530,
    "startIndex": 1,
    "pageSize": 10,
    "currentPage": 1,
    "pages": 5453,
    "orderBy": "newest",
    "results": [{
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Net neutrality has its day in court – with lawyers, Christians and the Cheshire Cat",
        "webPublicationDate": "2015-12-05T12:30:06Z",
        "id": "technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "sectionName": "Technology"
    }, {
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Five things we love: from a school-proof tablet to a ghostly Serbian bicycle",
        "webPublicationDate": "2015-12-05T10:00:02Z",
        "id": "technology/2015/dec/05/five-things-we-love",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/05/five-things-we-love",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/05/five-things-we-love",
        "sectionName": "Technology"
    }, {
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Don’t listen to those who try to own the definition of a video game",
        "webPublicationDate": "2015-12-04T12:00:21Z",
        "id": "technology/2015/dec/04/video-games-gaming-dudegamers",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/04/video-games-gaming-dudegamers",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/04/video-games-gaming-dudegamers",
        "sectionName": "Technology"
    }]
}
}

这不包括文章文本,只包括新闻页面的网址。我的问题是如何获得文章文本?

EN

回答 2

Stack Overflow用户

发布于 2015-12-05 16:59:34

尝试将show-blocks=all&添加到query。返回的属性"bodyTextSummary"在url。下面的URL可以细分为:

Basic网址: http://content.guardianapis.com/search?

搜索参数的开始: q=

搜索参数(所有“”替换为"%20"): 12%20years%20a%20slave&

转换为json格式: format=json&

按特定标记筛选: tag=film/film,tone/reviews&

按开始日期筛选: from-date=2010-01-01&

按相关性排序: order-by=relevance&

显示完整的API哈希: show-blocks=all&

您的API键(应该将您的密钥放在"test"): api-key=test

http://content.guardianapis.com/search?q=12%20years%20a%20slave&format=json&tag=film/film,tone/reviews&from-date=2010-01-01&order-by=relevance&show-blocks=all&api-key=test

请参阅http://open-platform.theguardian.com/documentation/search

票数 7
EN

Stack Overflow用户

发布于 2017-06-18 05:39:21

使用show-fields键和bodyText键值对您的URL,然后您将获得内容。

例如:show-field=BodyText

http://content.guardianapis.com/search?order-by=newest&show-fields=bodyText&q=politics&api-key=test

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34108030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档