PHP 总结任意 URL
在 PHP 中,如何获取任意 URL 的摘要?总而言之,我的意思是类似于 Google 网络搜索结果中的 URL 描述。
这可能吗?是否已经有某种我可以插入的工具,这样我就不必生成自己的摘要?
如果可能的话,我不想使用元数据描述。
-迪伦
How can I, in PHP, get a summary of any URL? By summary, I mean something similar to the URL descriptions in Google web search results.
Is this possible? Is there already some kind of tool I can plug in to so I don't have to generate my own summaries?
I don't want to use metadata descriptions if possible.
-Dylan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Google 中显示的(通常)是 META 描述标签。如果您不想使用它,也可以使用页面标题。
What displays in Google is (generally) the META description tag. If you don't want to use that, you could use the page title instead though.
如果您不想使用元数据描述(顺便说一句,这正是它们的用途),您需要做大量的研究和工作。本质上,您必须猜测页面的哪一部分是内容,哪一部分只是导航/绒毛。事实上,谷歌正是这样的;但请注意,从无用的废话中提取有价值的信息是他们的第一能力,十年来他们一直在研究和改进这一能力。
当然,您可以进行有根据的猜测(例如“查找具有 ID 或类
maincontent
的元素”并从中获取第一段),也许就可以了。真正的问题是,您希望结果有多好? (Facebook 有类似的网站链接,有时摘要只是坚持广告是主要内容)。If you don't want to use metadata descriptions (btw, this is exactly what they are for), you have a lot of research and work to do. Essentially, you have to guess which part of the page is content and which is just navigation/fluff. Indeed, Google has exactly that; note however, that extracting valuable information from useless fluff is their #1 competency and they've been researching and improving that for a decade.
You can, of course, make an educated guess (e.g. "look for an element with ID or class
maincontent
" and get the first paragraph from it) and maybe it will be OK. The real question is, how good do you want the results to be? (Facebook has something similar for linking to websites, sometimes the summary just insists that an ad is the main content).下面将允许您解析页面的
title
标记的内容。注意:必须将 php 配置为允许file_get_contents
检索 URL。否则,您必须使用curl
来检索页面 HTML。The following will allow you to to parse the contents of a page's
title
tag. Note: php must be configured to allowfile_get_contents
to retrieve URLs. Otherwise you'll have to usecurl
to retrieve the page HTML.虽然我讨厌推广服务,但我发现了这个:
embed.ly
它有一个 API,可以返回包含您需要的所有数据的 JSON。
但我仍在寻找一个免费/开源库来完成同样的事情。
While i hate promoting a service i have found this:
embed.ly
It has an API, that returns a JSON with all the data you need.
But i am still searching for a free/opensource library to do the same thing.