【发布时间】:2020-04-03 20:40:46
【问题描述】:
我想调用 Apify 演员并通过调用 Apify API 来指定参数值。
演员是Google Search Results Scraper located here。
Here is where the docs say 使用queries 作为 API 调用负载中的对象属性名称。
下表显示了由其输入模式定义的参与者 INPUT 字段的规范。当使用 API 运行 actor 时,可以 [...] 在 JSON 对象中提供这些字段。在文档中阅读更多内容。
...
搜索查询或网址
Google 搜索查询(例如纽约市的食物)和/或完整网址(例如https://www.google.com/search?q=food+NYC)。
每行输入一项。
可选
JSON 示例
类型:字符串"queries": "Hotels in NYC Restaurants in NYC https://www.google.com/search?q=restaurants+in+NYC"
运行我的 Google Apps 脚本代码后,我希望看到 searchQueries.term 参数发生如下变化。
"searchQuery": {
"term": "Banks in Phoenix", // what I am trying to change to by API call
// [...]
},
但我实际得到的是与上次手动运行actor时相同的参数值。如下。
Apify——我实际看到的"searchQuery": {
"term": "CPA firms in Newark", // remaining from last time I ran the actor manually
// [...]
},
这是我从 Google Apps 脚本运行的代码。
代码.gsconst runSearch = () => {
const apiEndpoint= `https://api.apify.com/v2/actor-tasks/<MY-TASK-NAME>/run-sync?token=<MY-TOKEN>`
const formData = {
method: 'post',
queries: 'Banks in Phoenix',
};
const options = {
body: formData,
headers: {
'Content-Type': 'application/json',
},
};
UrlFetchApp.fetch(apiEndpoint, options,);
}
我做错了什么?
【问题讨论】:
-
查询看起来不错。我只是不知道 UrlFetchApp 的详细信息。通常,您需要发送正文:JSON.stringify(formData) 和方法:'POST'
-
您没有收到任何错误消息吗?另外,您能否尝试遵循@LukášKřivka 建议在体内使用
JSON.stringify(formData)并让我知道这是否有效?谢谢!
标签: google-apps-script web-scraping apify