以编程方式检查远程网站是否“显示”特定的 html 元素

发布于 2024-11-19 16:58:23 字数 116 浏览 0 评论 0原文

我想要求我的免费用户添加一个链接回我的网站。但是,我想以编程方式检查它们确实添加了我提供的 linkback html 元素,并且没有被某种 CSS 和 Javascript 隐藏。

有什么好的建议吗?

I want to require my free users to add a linkback to my website. But, I want to check it programmatically that indeed they added the linkback html element I provided and was not hidden by some sort of CSS and Javascript.

Any good suggestions?

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

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

发布评论

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

评论(2

情域 2024-11-26 16:58:23

我不是这方面的专家,但我想说最简单、最可靠的方法是在浏览器中实际渲染页面,以确保所有 CSS 和 JavaScript 都以用户看到的相同方式应用。

显然您不想自己执行此操作,但我假设您的网站有一个页面,用户告诉您他们已添加了链接,或者他们根据该链接请求免费使用。此时,您可以将其页面加载到隐藏的 IFrame 中,然后使用 JavaScript(JQuery 无疑是最简单的)来查找您的链接并查询其可见性。

这可能会因跨域安全问题(访问 IFrame 的内容)而变得复杂,但服务器上的代理可以轻松解决此问题。

如果不使用浏览器和 JavaScript,我可以想象解析他们的 HTML、CSS 和 JavaScript 服务器端并查找您的链接不可见的任何提示将是一项艰巨的工作 - 因为有很多方法可以隐藏它(即使是偶然)。

Not an expert on this matter but I'd say the easiest and most reliable method involves actually rendering their page in a browser to ensure that all CSS and JavaScript is applied in the same way a user would see.

Obviously you don't want to do this yourself, but I assume your site has a page where users tell you that they've added the link to it, or where they request free usage based on that link. At this point you could load their page into a hidden IFrame then use JavaScript (JQuery would undoubtedly be easiest) to find your link and query its visibility.

This may be complicated by cross-domain security issues (accessing the IFrame's content) but a proxy on your server could easily work around this.

Without using a browser and JavaScript I can imagine it would be a huge job to parse their HTML, CSS and JavaScript server-side and look for any hint that your link isn't visible - as there are plenty of ways it could be hidden (even by accident).

丿*梦醉红颜 2024-11-26 16:58:23
$my_link = '<a href="http://www.myamazingsite.com/" title="Magic Stuff">Total Amazing Magic Tricks</a>';
$remote_html = file_get_contents('http://www.remotesite.com/some-amazing-page.php');
if(strpos($remote_html, $my_link) === false){
    // link was not found
}

除非您有足够的计算能力和编程知识来设置模拟,否则您将无法轻松判断链接是否被 CSS 或 JS 隐藏。

$my_link = '<a href="http://www.myamazingsite.com/" title="Magic Stuff">Total Amazing Magic Tricks</a>';
$remote_html = file_get_contents('http://www.remotesite.com/some-amazing-page.php');
if(strpos($remote_html, $my_link) === false){
    // link was not found
}

You WON'T be able to easily tell if the link is hidden by CSS or JS unless you have enough computing power and programming knowledge to setup a simulation.

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