我想获取文件源并将其包装在JSONP中。
例如,我想从我不拥有的主机中检索pets.txt作为文本。我想通过只使用客户端 JavaScript 来做到这一点。
我正在寻找可以将任何内容转换为 JSONP 的在线服务。
YQL
雅虎查询语言就是其中之一。
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://elv1s.ru/x/pets.txt"&format=json&callback=grab
如果 URL 未被 robots.txt 阻止,则此方法有效。YQL尊重 robots.txt。我无法获取http://userscripts.org/scripts/source/62706.user.js因为它被robots.txt阻止了。
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://userscripts.org/scripts/source/62706.user.js"&format=json&callback=grab
"forbidden":"robots.txt 域不允许抓取 url: http://userscripts.org/scripts/source/62706.user.js "
所以我正在寻找另一种解决方案。