获取html跨站,显示并获取元素值

发布于 2024-10-06 13:26:57 字数 1854 浏览 5 评论 0原文

我需要从 aspx 站点获取完整的输出。当用户离开时,我会将某些特定元素中的内容保存在 cookie 中。问题是 aspx 位于我无权访问的域上。我希望输出的行为与 iframe 中一样,因此链接需要可单击,但它不会离开我的页面。

我想到的是带有 PHP 代理的 AJAX 或可以修改内容的 iframe。 这可能吗? 如果可能并且涉及服务器端代码,我想知道是否有任何支持完整代码的免费网络主机(例如几乎每个免费网络主机都为 PHP 启用了 safe_mode )。

编辑:我想显示此页面: 学校计划。 URL 不会改变,它只是向服务器发送请求(通过 JavaScript 思考)。当用户离开时,我将看到选择框 id="TypeDropDownList" 中的内容以及选择框 id="ScheduleIDDropDownList" 中的内容。

当用户返回到我的页面时,我将通过 URL 将这些值打印到页面,如下所示 "http://www.novasoftware.se/webviewer/(S(lv1isca2txx1bu45c3kvic45))/design1.aspx?schoolid=27500& code=82820&type=" + type + "&id=" + id + "

在我在这里发布之前,我在 000webhost 上尝试了几个 php 代理脚本。 例如这个:

<?php
ob_start();

function logf($message) {
  $fd = fopen('proxy.log', "a");
  fwrite($fd, $message . "\n");
  fclose($fd);
}

?>
<?
$url = $_REQUEST['url'];
logf($url);
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, "Owen's AJAX Proxy");

$content = curl_exec($curl_handle);
$content_type = curl_getinfo($curl_handle, CURLINFO_CONTENT_TYPE);
curl_close($curl_handle);
header("Content-Type: $content_type");
echo $content;
ob_flush();
?>

但它返回警告:curl_setopt():提供的参数不是 /home/a5379897/public_html/ajax-proxy.php 中第 16 行的有效 cURL 句柄资源

我试图就此联系他们,因为他们说他们有cURL 已启用,但他们尚未回复。

我认为当用户第一次访问该页面时可以只显示两个选择框。选择选项后,它将使 iframe 通过传递“http://www.novasoftware.se/webviewer/(S(lv1isca2txx1bu45c3kvic45))/design1.aspx?schoolid=27500&code=82820&type=”来显示正确的页面+ type + "&id=" + id + " 到 src 属性。 问题是我需要以某种方式检索选择框,我也会遇到同样的问题。

I need to get the complete output from an aspx site. When the user leaves I will save what's in some specific elements in cookies. The problem is that the aspx is on a domain I don't have access to. I want the output to behave as in an iframe so links need to be clickable but it won't leave my page.

I think of either AJAX with PHP-proxy or an iframe that I can modify content in.
Is this possible?
If it is possible and it involves server-side code I would like to know if there are any free web hosts that support the full code( for example almost every free web host has safe_mode on for PHP).

EDIT: I want to display this page : School scheme. The URL doesn't to change, it just sends requests to the server (think via JavaScript). When the user leaves I will see what's in the select box id="TypeDropDownList" and what's in the select box id="ScheduleIDDropDownList".

When the user returns to my page I will print those values to the page via URL like this "http://www.novasoftware.se/webviewer/(S(lv1isca2txx1bu45c3kvic45))/design1.aspx?schoolid=27500&code=82820&type=" + type + "&id=" + id + "

I tried several php proxy scripts on 000webhost before I posted here.
for example this :

<?php
ob_start();

function logf($message) {
  $fd = fopen('proxy.log', "a");
  fwrite($fd, $message . "\n");
  fclose($fd);
}

?>
<?
$url = $_REQUEST['url'];
logf($url);
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, "Owen's AJAX Proxy");

$content = curl_exec($curl_handle);
$content_type = curl_getinfo($curl_handle, CURLINFO_CONTENT_TYPE);
curl_close($curl_handle);
header("Content-Type: $content_type");
echo $content;
ob_flush();
?>

But it returns Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/a5379897/public_html/ajax-proxy.php on line 16

I tried to contact them about this because they say they have cURL enabled but they haven't responded yet.

I think it would be possible to just display the two select boxes when the user first visit the page. When options is selected it will make an iframe show the right page by passing "http://www.novasoftware.se/webviewer/(S(lv1isca2txx1bu45c3kvic45))/design1.aspx?schoolid=27500&code=82820&type=" + type + "&id=" + id + " to the src attribute.
The problem with that is that I will need to retrieve the select boxes someway and I will have the same problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南街九尾狐 2024-10-13 13:26:57

您需要使用 PHP,因为 Javascript 不允许跨域请求。您的 PHP 代码实际上会抓取客户端想要的页面,对其进行处理(使用原始 href 链接到的页面的 get 变量将链接的 href 更改为您的页面)。当他们单击链接时,他们将被发送到他们现在所在的同一页面,但该页面将抓取新页面并返回该页面(也处理该页面)等等。

000webhost 是一个不错的免费网络主机,它允许您执行大部分 PHP 功能,并且不会在您的网站上放置广告。

You would need to use PHP as Javascript doesn't doesn't allow cross domain requests. Your PHP code would literally grab the page the client wants, process it (changing link's href to your page with a get variable of the page the original href links to). When they click the link they will be sent to the same page they are on now but the page will grab the new page and return that(processing that page too) and so on.

000webhost are a nice free webhost that allow you to do most of PHP's functions and don't put adverts on your site.

挽手叙旧 2024-10-13 13:26:57

要将整个 aspx 输出作为字符串进行操作,您可以使用 file_get_contents(http://yoursite.com/yourpage.aspx);

为了获得最佳结果,请通过 http 打开一个流作为上下文。

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>

To get the whole aspx output as a string to manipulate, you can use file_get_contents(http://yoursite.com/yourpage.aspx);

For best results, open a stream as the context via http.

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>
醉生梦死 2024-10-13 13:26:57

感谢 greg,我可以创建这个获取页面的脚本。

<html>
<head>
</head>
<body>
<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);
$host = 'http://www.novasoftware.se/webviewer/(S(bkjwdqntqzife4251x4sdx45))/';
$url = '/design1.aspx?schoolid=27500&code=82820&type=3&id={7294F285-A5CB-47D6-B268-E950CA205560}';
$changetothis='src="'.$host;
// Open the file using the HTTP headers set above
$file = file_get_contents($host.$url, false, $context);
$changed = str_replace('src="', $changetothis,$file);
echo $changed;

?>
</body>
</html>

Thanks to greg I could create this script that gets the page.

<html>
<head>
</head>
<body>
<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);
$host = 'http://www.novasoftware.se/webviewer/(S(bkjwdqntqzife4251x4sdx45))/';
$url = '/design1.aspx?schoolid=27500&code=82820&type=3&id={7294F285-A5CB-47D6-B268-E950CA205560}';
$changetothis='src="'.$host;
// Open the file using the HTTP headers set above
$file = file_get_contents($host.$url, false, $context);
$changed = str_replace('src="', $changetothis,$file);
echo $changed;

?>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文