Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在Google Apps脚本中使用UrlFetchApp获取网页并解决服务器错误代码500_Google Apps Script_Web Scraping_Google Sheets_Internal Server Error_Server Error - Fatal编程技术网

Google apps script 在Google Apps脚本中使用UrlFetchApp获取网页并解决服务器错误代码500

Google apps script 在Google Apps脚本中使用UrlFetchApp获取网页并解决服务器错误代码500,google-apps-script,web-scraping,google-sheets,internal-server-error,server-error,Google Apps Script,Web Scraping,Google Sheets,Internal Server Error,Server Error,我想使用谷歌应用程序脚本从YellowPages.com获取一些列表数据。使用GAS中的UrlFetchApp.fetch(url)(如下所示),服务器抛出500错误。但是,我可以在同一URL上的Google工作表中成功地使用IMPORTXML(),而且效果很好 是什么解释了这种行为上的差异?在Google Apps脚本中,我可以做些什么不同的事情来实现我从IMPORTXML()获得的相同的、期望的结果 谷歌表单 行为如预期。结果是一个链接数组 谷歌应用程序脚本 代码.gs 行为不符合预期。结果

我想使用谷歌应用程序脚本从YellowPages.com获取一些列表数据。使用GAS中的
UrlFetchApp.fetch(url)
(如下所示),服务器抛出500错误。但是,我可以在同一URL上的Google工作表中成功地使用
IMPORTXML()
,而且效果很好

是什么解释了这种行为上的差异?在Google Apps脚本中,我可以做些什么不同的事情来实现我从
IMPORTXML()
获得的相同的、期望的结果

谷歌表单 行为如预期。结果是一个链接数组

谷歌应用程序脚本 代码.gs 行为不符合预期。结果是500个错误

错误消息:
Exception: Request failed for https://www.yellowpages.com returned code 500. Truncated server response: <html>
 <head><title>500 Internal Server Error</title></head>
 <body>
 <center><h1>500 Internal Server Error</h1></center>
 <hr><center>openresty</... (use muteHttpExceptions option to examine full response) (line 16, file "Code")
异常:请求失败https://www.yellowpages.com 返回代码500。截断的服务器响应:
500内部服务器错误
500内部服务器错误


openrest我认为这个网站可能会以某种方式阻止从
UrlFetchApp
发出的请求(我尝试使用其他几种工具发出请求,但在其他任何地方都能正常工作)。根据您的具体情况,您可能希望将脚本发布为web应用程序并使用。@Iamblichus:但是服务器可能会看到什么,让它将
UrlFetchApp
标识为请求的源?它们都是未经验证的
GET
请求,对吗?谷歌服务器的IP地址是我唯一能想到的。但是,假设谷歌循环使用其服务器,它应该只会被所有请求的一个子集阻止。对的想法?例如,如果您仍在寻找这个问题的解决方案,那么这第一个脚本有用吗?另外,关于您的问题的原因,在“添加:”部分的实验如何?我认为这个网站可能会以某种方式阻止从
UrlFetchApp
发出的请求(我尝试使用其他几种工具发出请求,但在其他任何地方都能正常工作)。根据您的具体情况,您可能希望将脚本发布为web应用程序并使用。@Iamblichus:但是服务器可能会看到什么,让它将
UrlFetchApp
标识为请求的源?它们都是未经验证的
GET
请求,对吗?谷歌服务器的IP地址是我唯一能想到的。但是,假设谷歌循环使用其服务器,它应该只会被所有请求的一个子集阻止。对的想法?例如,如果您仍在寻找这个问题的解决方案,那么这第一个脚本有用吗?还有,关于你的问题的原因,在“补充:”部分的实验怎么样?
const ENDPOINT = 'https://www.yellowpages.com/al/accounting-services';
const main = () => {
  const response = UrlFetchApp.fetch( ENDPOINT, );
  const responseContentText = response.getContentText();
  Logger.log('(line 5) responseContentText\n%s', responseContentText,);
  return responseContentText;
}
Exception: Request failed for https://www.yellowpages.com returned code 500. Truncated server response: <html>
 <head><title>500 Internal Server Error</title></head>
 <body>
 <center><h1>500 Internal Server Error</h1></center>
 <hr><center>openresty</... (use muteHttpExceptions option to examine full response) (line 16, file "Code")