使用jQuery获取网站信息 [英] Get website information with jQuery

查看:97
本文介绍了使用jQuery获取网站信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery,有没有办法获取网站信息(可能是元数据和图像)?我要完成的一个示例是,当我在Facebook上共享链接时,它会拉出相关图像并显示网站(文章)中的文字内容.

Using jQuery, is there a way to get website information (possibly meta data and images)? An example of what I'm trying to accomplish is when I share a link on facebook it pulls up relevant images and show a blurb of text from the website (article).

有没有一种方法可以使用jQuery(带有Ajax)轻松完成此任务?

Is there a way to accomplish this easily using jQuery (with ajax)?

推荐答案

好吧,我认为您不能仅通过Javascript(jQuery)来实现这一目标.由于AJAX调用的同源策略,您不能直接请求信息.但是您可以使用url将AJAX调用发送到您自己的应用程序,这样它将下载有问题的页面并解析其元标记和标题.并以正确的格式返回响应.

Well, I think you cannot achieve this by Javascript(jQuery) alone. Because of the same-origin policy of AJAX calls you cannot request the information directly. But you could send an AJAX call to your own application with the url, so it would download the page in question and parse its meta tags and title. And return a response in the proper format.

另一个想法是让服务器实际浏览页面并对其进行屏幕截图,并可能保留每个域的按比例缩小图像的数据库,但我不知道它在计算上会花费多少,但是比单纯解析更糟糕.

Another idea would be to make the server actually browse the page and make a screenshot of it and maybe keep a database of scaled-down images for each domain, I don't know how computationally expensive it would be however, seems a lot worse than simply parsing.

请参阅wkhtmltoimage

这篇关于使用jQuery获取网站信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆