我在从“卫报”获得新闻API的文章文本时遇到了问题。我有一个url,它是这样的:http://content.guardianapis.com/search?section=technology&api-key=MYKEY和我得到的响应如下:
{
"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"
}]
}
}这不包括文章文本,只包括新闻页面的网址。我的问题是如何获得文章文本?
发布于 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
发布于 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
https://stackoverflow.com/questions/34108030
复制相似问题