javascript - 如何在内容/风格有所变化的情况下为外部网站提供服务?

标签 javascript html css angularjs angular

我正在尝试建立一个允许人们使用这个的信息亭 URL只是为了打印收据。所以我必须隐藏标题和其他允许退出页面的链接。

这是我到目前为止尝试过的方法,但没有成功:

  1. 带有将 CSS 附加到页面的 JS 脚本的 iframe:由于 CORS 政策而失败。
  2. 使用本地主机上的 Apache 或 NGINX 代理通过 iframe 绕过 CORS block :仍在尝试中。
  3. 带有 file_gets_content + str_replace 的 PHP:修复了所有 404 错误,但结果仍然是空白页。

这是代码:

<?php
$content = file_get_contents('https://www.lottomatica.it/scommesse/avvenimenti');
$content = str_replace(
    '</title>',
    '</title><base href="https://www.lottomatica.it/">', 
$content);
$content = str_replace(
    '/etc/',
    'https://www.lottomatica.it/etc/', 
$content);
$content = str_replace(
    '/content/',
    'https://www.lottomatica.it/content/', 
$content);
$content = str_replace(
    '</head>',
    '<style>
        header {
            display: none!important;
        }
    </style>
    </head>', 
$content);
echo $content; ?>

我不需要使用特定技术,只需提取页面内容、隐藏页眉和其他一些部分,然后在本地主机上为 Chrome Kiosk 应用程序提供服务。任何帮助将不胜感激!

最佳答案

我为我们使用的播客提要生成服务做了一些类似的事情。我们将我们的内容发布给他们,他们为提要生成所有 xml 标记,但我想在我们的服务器上托管提要并让它看起来像是我们做的一切。

我正在使用由 sub_filter 构建的 Nginx模块,我的位置 block 看起来像这样:

location /podcast {
    sub_filter_types text/xml;
    sub_filter '<atom:link href="http://<provider-url>/path/podcast/'  '<atom:link href="https://my-website.com/podcast/';
    sub_filter '<link>http://<provider-url>/path/</link>' '<link>https://my-website.com/</link>';
    sub_filter_once off;
    sub_filter_last_modified on;
    proxy_set_header Accept-Encoding "";
    proxy_pass https://<provider-url>/path/podcast/;
}

另一种选择是您可以在 Nginx 中设置一个位置 block ,该 block 代理他们的站点不变到您服务器上的 url,然后将您现有的 javascript 代码指向该 url。然后您将获得没有 CORS 问题的内容,但任何查看控制台的人都可以在打开该链接时找出内容的来源。

关于javascript - 如何在内容/风格有所变化的情况下为外部网站提供服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51901943/

相关文章:

javascript - 无法使用 Selenium 在自定义滚动条上滚动

javascript - 使用 Jasmine 测试 javascript 警报

javascript - 制作 div 滚动会导致它抖动

CSS3 过滤器 : drop-shadow spread property alternatives

带空格的 HTML 列表

javascript - 检查文本的 URL,然后使用 jquery 或 js 将类添加到 li

javascript - 我删除了 package.json 和 Gruntfile.js,现在 Grunt 将不会加载依赖项

html - 容器中的 Twitter Bootstrap 内容未居中

html - Firefox 中的导航项未呈现在正确的位置

css - 在 100% div 内获取水平滚动条