Javascript 如何为内容/风格发生变化的外部网站提供服务?

Javascript 如何为内容/风格发生变化的外部网站提供服务?,javascript,html,css,angularjs,angular,Javascript,Html,Css,Angularjs,Angular,我正在尝试建立一个信息亭,允许人们使用它来打印收据。因此,我必须隐藏允许退出页面的标题和其他链接 这是我迄今为止一直尝试的,但没有成功: 带有JS脚本的iframe将css附加到页面:由于CORS策略而失败 在localhost上使用Apache或NGINX进行代理传递,以使用iframe绕过CORS块:仍在尝试 带有文件的PHP获取内容+str\u替换:修复了所有404错误,但仍然得到一个空白页 代码如下: <?php $content = file_get_contents('http

我正在尝试建立一个信息亭,允许人们使用它来打印收据。因此,我必须隐藏允许退出页面的标题和其他链接

这是我迄今为止一直尝试的,但没有成功:

  • 带有JS脚本的iframe将css附加到页面:由于CORS策略而失败
  • 在localhost上使用Apache或NGINX进行代理传递,以使用iframe绕过CORS块:仍在尝试
  • 带有
    文件的PHP获取内容
    +
    str\u替换
    :修复了所有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; ?>
    

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

    我使用的是与模块一起构建的Nginx,我的位置块如下所示:

    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/;
    }
    
    位置/播客{
    sub_filter_type text/xml;
    
    sub_filter'老话题,只是想分享一下我在这方面的经验

    尝试了不同的解决方案。第一个可行的方法是在开始时使用chrome devtools注入自定义css和js。它可行,但效率低下,并且在6个多小时的会话中还会导致一些随机崩溃

    最后一个正在开发的、目前正在生产的解决方案也是优雅的,它使用一个定制的chrome扩展,向特定页面添加特定的css/脚本,还包含定制函数、处理程序、更新、身份验证等的代码


    希望这能帮助别人。

    你可以使用它从外部网站中提取特定元素,但它不会带来样式或类似的东西。也许这对你有用。忘了提到你需要在URL中使用#elementId来获取该元素你也可以使用他们的css URL来提取他们样式的副本…@TJBlackman很好的专业提示,我必须记住这一点。老实说,在别人指出这一点后,这是显而易见的,但有人不是我。哈哈-最好只是检查CSS,并复制您需要的内容。然后您可以编辑它,避免过多的代码开销,但是…当您懒惰的时候,就抓住一切!