urlfetchapp.fetch()似乎不改变用户代理
尝试使用Google Apps脚本从网站获取数据,以将其直接放入电子表格中。 python请求等效效果很好的情况似乎不起作用。
Python代码:
page = requests.get("someurl?as_data_structure", headers={'user-agent':'testagent'})
燃气代码:
var page = UrlFetchApp.fetch("someurl?as_data_structure", headers={'user-agent':'testagent'});
唯一必需的标题是用户代理,如果我不包括标题,我通常会从Python代码中获得的错误是我通常会从Python代码中获得的。我是JS的新手,但据我所知,这是正确的方法。
编辑: 现在将标题放在正确的位置,但问题仍然存在,与以前完全相同。
var options = {"headers": {"User-Agent": "testagent"}};
var page = UrlFetchApp.fetch("someurl?as_data_structure", options);
Trying to grab data from a website using Google Apps Script to put it directly into a spreadsheet. The fetch does not seem to be working, where the Python requests equivalent works just fine.
Python code:
page = requests.get("someurl?as_data_structure", headers={'user-agent':'testagent'})
GAS code:
var page = UrlFetchApp.fetch("someurl?as_data_structure", headers={'user-agent':'testagent'});
The only required header is the user-agent, and the error I am getting from the GAS code is what I would usually get from the Python code if I hadn't included the header. I am new to js but as far as I know this is the proper way to do it..?
EDIT:
Now got the headers in the right place but the issue persists, exactly the same error as before.
var options = {"headers": {"User-Agent": "testagent"}};
var page = UrlFetchApp.fetch("someurl?as_data_structure", options);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Star★(在左上方)问题在这里让Google开发人员优先考虑此问题。
Google并不总是记录其限制(烦人?)。这样的限制是更改用户代理。它是修复的,
无法更改它。
样本测试:
样本响应:
它也不能准确返回要提出的请求。
Star ★(on top left) the issue here for Google developers to prioritize the issue.
Google doesn't always document it's restrictions(Annoying?). One such restriction is changing the user agent. It's fixed to
You can't change it.
Sample Test:
Sample Response:
Neither does it accurately return the request that would be made.
标题
属于选项:the
headers
belong into the options: