跨域-检索页面源 [英] CROSS-DOMAIN - Retrieve Page Source

查看:69
本文介绍了跨域-检索页面源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个项目正在工作,我们需要另一个域的特定值,但我无权更改(因此,我无法嵌套iframe或CORS).我们需要保持Session/Cookie状态不变,以根据令牌在页面上的用户变化来从页面获取所需的数据.因此,服务器端解决方案将无法正常工作.

Hi I have a project here at work where we need a specific value from another domain I do not have access to change (So I can't do nested iframes, or CORS). We need to keep Session/Cookie state the same to get the required data from the page as the token changes based on the user on the page. So a server side solution wouldn't work.

解决此问题的最佳方法是什么,以下是页面源代码的全部内容. 我需要检索FF321332值

What is the best way to go about this, the following is what the page source is in it's entirety. I need to retrieve the FF321332 value

{"<!--":"","token":"FF321332","expire":1317448445,"":"--><body onload=document.body.innerHTML=clear>"}

到目前为止,我尝试过的一些事情是动态脚本标签"它引发JS错误意外令牌:错误,jQuery(.getScript)引发相同错误,任何其他形式的.get或xhr都会引发跨域错误错误.

Some things I've tried so far are Dynamic Script Tags "It throws a JS error Unexpected token : error, Jquery (.getScript ) this throws the same error, any other form of .get or xhr will throw a Cross Domain Error.

我感觉自己在使用.getScript或Dynamic Sc​​ript标签的正确轨道上,因为它几乎想读入它.但是,如果我能解决Unexpected token错误并以文本形式读入(如果是的话)可能)我可以将变量解析为普通文本.

I feel like I was on the right track with the .getScript or Dynamic Script Tags as it almost wants to read it in. But if I can get around the Unexpected token error and just read it in as text (if this is possible) I can just parse out the variable as normal text.

在此方面的任何帮助将不胜感激.

Any assistance in this would be greatly appreciated.

推荐答案

JSONP允许您执行您想做的事情.查看有关如何使.get使用JSONP来避免浏览器跨域强制实施的jQuery文档.

JSONP allows you to do what you are trying to do. Check out the jQuery doc on how to make your .get use JSONP to side step the browser cross-domain enforcement.

本质上,当您执行$ .getJSON时,如果url中有一个写着"callback ="+的内容",那么它将把它视为jsonp而不是标准的getjson.

Essentially, when you do $.getJSON, if the url has a piece that says "callback=" + whatever, then it will treat it as jsonp instead of the standard getjson.

祝你好运.

这篇关于跨域-检索页面源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆