以编程方式检查远程网站是否“显示”特定的 html 元素
我想要求我的免费用户添加一个链接回我的网站。但是,我想以编程方式检查它们确实添加了我提供的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是这方面的专家,但我想说最简单、最可靠的方法是在浏览器中实际渲染页面,以确保所有 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).
除非您有足够的计算能力和编程知识来设置模拟,否则您将无法轻松判断链接是否被 CSS 或 JS 隐藏。
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.