我的目标是通过API调用必应新闻搜索来获得匹配某个查询的结果。
我在用Zapier。我使用的是代码步骤,它可以采用Python或JavaScript。我目前有Python代码来调用API,如下所示...
headers = {
'Content-Type': 'text/plain',
'Ocp-Apim-Subscription-Key': 'my_api_key'
}
r = requests.get('https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=%22Donald%20Trump%22&textDecorations=true&textFormat=HTML&sortBy=Date&freshness=Day', headers=headers)
output = [{'assets': r.json()}]
这个很管用。它成功地调用并获得结果。
// stores an array of any length (0 or more) with the matches
var matches = inputData.body.match(/\b[\w-]{32}\b/g)
if (matches == null) {
return { str: "false" }
}
return matches.map(function (m) { return {str: m} })
每个代码示例的最后一行似乎掌握着关键...在Javascript中,映射某些东西某些东西...?
下面是一个响应示例,每个请求...
{
"_type": "News",
"readLink": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22",
"queryContext": {
"originalQuery": "\"Donald Trump\"",
"adultIntent": false
},
"totalEstimatedMatches": 73200,
"sort": [
{
"name": "Best match",
"id": "relevance",
"isSelected": false,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22"
},
{
"name": "Most recent",
"id": "date",
"isSelected": true,
"url": "https://api.cognitive.microsoft.com/api/v7/news/search?q=%22Donald+Trump%22&sortby=date"
}
],
"value": [
{
"name": "Democrats to <b>Donald Trump</b>: Here's a Bill to Outlaw Family Separation",
"url": "https://www.rollingstone.com/politics/news/democrats-give-trump-a-bill-to-outlaw-family-separation-w521650",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E5F488C11B8B2C7578200936C34BA0C3&pid=News",
"width": 700,
"height": 394
}
},
"description": "All 49 Democrats in the Senate have signed on to a bill that would end Trump's policy of "child-snatching" A two-year-old Honduran asylum seeker cries as her mother is searched and detained near the U.S.-Mexico border on June 12th, 2018 in McAllen, Texas.",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5e00ddc3-bb67-a2c7-702a-929095be2f19",
"name": "Bill"
}
],
"provider": [
{
"_type": "Organization",
"name": "Rolling Stone"
}
],
"datePublished": "2018-06-19T09:39:00.0000000Z",
"category": "Politics"
},
{
"name": "Republicans break from Trump on migrant family separation",
"url": "https://www.nbcnews.com/politics/first-read/republicans-break-trump-migrant-family-separation-n884171",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.7225F1783FD189C842151F29E579409A&pid=News",
"width": 700,
"height": 367
}
},
"description": "WASHINGTON — The lowest points of <b>Donald Trump</b>’s presidency have tended to occur when a sizable portion of his own party has criticized him for his actions, policies and statements (even when the GOP doesn’t necessarily act on that criticism).",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "NBC News"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "Anger mounts against Trump over child separation policy",
"url": "https://www.aljazeera.com/news/2018/06/anger-mounts-trump-child-separation-policy-180618071221478.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.B6724EE606A4241FC8E9441331E20A67&pid=News",
"width": 700,
"height": 392
}
},
"description": "Pressure is mounting on US President <b>Donald Trump</b> to reverse his policy of separating children from refugees and migrants who cross the US-Mexico border. "Families belong together," protesters chanted on Sunday, as hundreds gathered outside detention ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"provider": [
{
"_type": "Organization",
"name": "Al Jazeera English"
}
],
"datePublished": "2018-06-19T09:38:00.0000000Z",
"category": "Politics"
},
{
"name": "President Trump Defends Immigration Policy, Says He Won't Let U.S. Became a 'Migrant Camp'",
"url": "https://www.msn.com/en-us/news/other/president-trump-defends-immigration-policy-says-he-wont-let-us-became-a-migrant-camp/ar-AAyOCt4",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.303D80992671B38688C86FEFC0F5F4B2&pid=News",
"width": 700,
"height": 498
}
},
"description": "WASHINGTON — Facing rising outrage from some Republicans as well as Democrats over the forced separation of migrant children and parents at the U.S.-Mexico border, President <b>Donald Trump</b> dug in Monday, again falsely blaming Democrats and declaring he ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
}
],
"mentions": [
{
"name": "Donald Trump"
},
{
"name": "United States"
},
{
"name": "Migrant worker"
}
],
"provider": [
{
"_type": "Organization",
"name": "Time"
}
],
"datePublished": "2018-06-19T09:36:00.0000000Z",
"category": "Politics"
},
{
"name": "Watch: <b>Donald Trump</b> awkwardly salutes a North Korean general at Singapore summit",
"url": "https://scroll.in/video/882762/watch-donald-trump-awkwardly-salutes-a-north-korean-general-at-singapore-summit",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D99B1336CDD2C22BFBD080E78C100052&pid=News",
"width": 600,
"height": 315
}
},
"description": "The North Korean state media aired a documentary on the recent Singapore summit, showing the meeting between Kim Jong Un and <b>Donald Trump</b>. Naturally, it wasn’t what the world had seen till then. While the 42-minute long KCTV documentary showed the entire ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f5ffb882-7230-f3fe-7141-cde5f4b5ed1a",
"name": "Singapore"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f28f12db-bc21-69f9-3860-1b24810b64ec",
"name": "Salute"
}
],
"provider": [
{
"_type": "Organization",
"name": "Scroll"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "World"
},
{
"name": "China accuses US of blackmailing after <b>Donald Trump</b>'s tariff threat",
"url": "http://www.newindianexpress.com/world/2018/jun/19/china-accuses-us-of-blackmailing-after-donald-trumps-tariff-threat-1830391.html",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.6A02D23B98FB3695CB79863006E25D86&pid=News",
"width": 600,
"height": 300
}
},
"description": "BEIJING: China today accused the US of "blackmailing" by threatening to slap additional tariffs on USD 200 billion of Chinese goods and warned that it would hit back with comprehensive measures if Washington went ahead with the plan. China's response came ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/5fcc3d97-0cf2-94e5-6dad-cd70e387bd69",
"name": "China"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z",
"category": "Business"
},
{
"name": "Family unity must be preserved: UN Chief Antonio Guterres on <b>Donald Trump</b>'s zero-tolerance immigration policy",
"url": "http://www.newindianexpress.com/world/2018/jun/19/family-unity-must-be-preserved-un-chief-antonio-guterres-on-donald-trumps-zero-tolerance-immigrati-1830399.html",
"description": "UNITED NATIONS: Children must not be traumatised by being separated from their parents, UN chief Antonio Guterres has said amid a growing backlash over US President <b>Donald Trump</b>'s hardline immigration policy which has resulted in the separation of hundreds ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/cba2f3bb-4714-89f7-8cd3-9cc8644da24b",
"name": "Zero tolerance"
}
],
"provider": [
{
"_type": "Organization",
"name": "The New Indian Express"
}
],
"datePublished": "2018-06-19T09:35:00.0000000Z"
},
{
"name": "<b>Donald Trump</b> has ordered the Pentagon to create the US Space Force",
"url": "https://www.technologyreview.com/the-download/611499/donald-trump-has-ordered-the-pentagon-to-create-the-us-space-force/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.D9DA1E8B8E5DA38E7C6F5D6F5D3FD23C&pid=News",
"width": 700,
"height": 393
}
},
"description": "The Space Force would constitute the sixth branch of the US armed forces. The news: During a meeting with the National Space Council today, President <b>Donald Trump</b> directed the Department of Defense and the Pentagon to begin work on the creation of the ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/f8e3b5fa-8d72-5bd7-c9c1-24ef1caf555a",
"name": "The Pentagon"
}
],
"provider": [
{
"_type": "Organization",
"name": "MIT Technology Review"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z"
},
{
"name": "Melania Trump “Hates To See” Children Separated From Their Families At Borders",
"url": "http://miami.cbslocal.com/2018/06/17/melania-trump-hates-children-separated-families/",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.E7697BA498AEE34B1399416F5C5B00DF&pid=News",
"width": 700,
"height": 466
}
},
"description": "President <b>Donald Trump</b> has repeatedly blamed the Democrats for the situation despite his administration instituting the policy change. “Democrats can fix their forced family breakup at the Border by working with Republicans on new legislation ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/6f7c7020-66da-2934-a3bb-190380654848",
"name": "Melania Trump"
}
],
"mentions": [
{
"name": "Melania Trump"
},
{
"name": "WFOR-TV"
},
{
"name": "Child"
}
],
"provider": [
{
"_type": "Organization",
"name": "CBS Miami"
}
],
"datePublished": "2018-06-19T09:32:00.0000000Z",
"category": "Politics"
},
{
"name": "Prince Harry said 'give <b>Donald Trump</b> a chance,' says Meghan Markle's father",
"url": "https://www.stuff.co.nz/life-style/104818877/Prince-Harry-said-give-Donald-Trump-a-chance-says-Meghan-Markles-father",
"image": {
"thumbnail": {
"contentUrl": "https://www.bing.com/th?id=ON.A5CE69ACF78448306EA41B1A47CCD62E&pid=News",
"width": 620,
"height": 349
}
},
"description": "Meghan Markle's father said that Prince Harry told him to give <b>Donald Trump</b> a chance and suggested that he was open about Britain's withdrawal from the European Union. In a lengthy interview with the British broadcaster ITV, Thomas Markle said Harry was an ...",
"about": [
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/1a466af2-ed23-25bd-794d-1ca925e4681b",
"name": "Donald Trump"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/ae7736c2-4291-bc85-8732-6d20c29ff943",
"name": "Prince Harry"
},
{
"readLink": "https://api.cognitive.microsoft.com/api/v7/entities/e4308957-a185-03fa-10ed-3c7b47fd0aea",
"name": "Meghan Markle"
}
],
"provider": [
{
"_type": "Organization",
"name": "Stuff.co.nz"
}
],
"datePublished": "2018-06-19T09:31:00.0000000Z"
}
]
}
我是David Zapier平台小组的。
听起来您已经理解了上面的Python部分,但我想解释一下是怎么回事。当从代码步骤返回项时,可能会发生以下几种情况:
对象
(Python的dict
),则所有键将被扁平化,数组将被整理,结果出现在上面的屏幕截图中数组
/列表
,则将为返回列表中的每个项运行后续步骤(所需的行为)问题内容: 我有从mongodb导出的json文件,如下所示: 大约有30000行,我想将每一行拆分成自己的文件。 (我正在尝试将我的数据转移到榻榻米群集上) 我尝试这样做: 但是我发现它似乎减少了行的负载,而当我期望30000个奇数时,运行此命令的输出仅给了我50个奇数文件! 有没有一种逻辑方法可以使此操作不使用任何适合的方法删除任何数据? 问题答案: 假设您不在乎确切的文件名,如果要将输入拆分
它是这样的: 插入some_table(col1,col2,col3,col4) 选择col1、col2、my_func(col3)为new_col3、col4 现在我需要使用相同的逻辑返回两个值而不是一个值。 我可以简单地编写另一个函数来执行相同的逻辑并返回第二个值,但这将是昂贵的,因为该函数从一个大的历史表中进行选择。 我不能与历史表进行连接,因为该函数没有执行简单的select。
我有一个字符串和一个ArrayList。字符串中有几个单词,用空格隔开,例如“firstword second third”。我想将字符串拆分为几个部分,并将“piece”字符串添加到ArrayList中。
问题内容: 如何在相同大小(= 10)的多个ArrayList中拆分ArrayList(size = 1000)? 问题答案: 你可以用来查看原始列表的一部分。 从API: 返回此列表在指定的(包括)和(不包括)之间的视图。(如果和相等,则返回的列表为空。)返回的列表由该列表支持,因此返回的列表中的非结构性更改会反映在此列表中,反之亦然。返回的列表支持此列表支持的所有可选列表操作。 例: Syst
问题内容: 我有以下代码: 我将有许多服务(如一项服务),并且我不想将它们全部放在同一个文件中。 我在Stack Overflow中读了另一个问题,我可能需要这样的其他文件:在该文件中写入所有服务,但是当我启动Node时会抛出该错误。 如何分隔代码? 问题答案: 您可以在不同的文件(例如 test-routes.js)中 定义路由,如下所示: 现在在您的主文件中说出 server.js, 您可以像
问题内容: 将Spring的配置拆分为多个xml文件的正确方法是什么? 此刻我有 /WEB-INF/foo-servlet.xml /WEB-INF/foo-service.xml /WEB-INF/foo-persistence.xml 我有以下内容: 实际问题: 这种方法正确/最佳吗? 我真的需要同时指定中的配置位置 和该板块? 我需要记住什么才能能够引用中定义的?这与 指定有关吗? 更新1: