PHP从页面中提取文章摘录 [英] PHP extract article excerpt from a page

查看:113
本文介绍了PHP从页面中提取文章摘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都不知道如何从任何给定的文章页面生成摘录(因此可以从多种类型的网站获取信息)吗?当您将网址粘贴到帖子中时,facebook会执行类似的操作.谢谢.

anyone have any idea how to generate excerpt from any given article page (so could source from many type of sites)? Something like what facebook does when you paste a url into the post. Thank you.

推荐答案

您要执行的操作称为 file_get_contents ),然后以某种方式解析它以获取所需的内容(即,从<body>标记中提取内容).

What you're looking to do is called web scraping. The basic method for doing so would be to capture the page (you can scrape a URL using file_get_contents), and then somehow parse it for the content that you want (ie. pull out content from the <body> tag).

为了解析返回的HTML,您应该使用DOM解析器. PHP具有自己的 DOM类,您可以使用.

In order to parse the returned HTML, you should use a DOM parser. PHP has its own DOM classes which you can use.

这篇关于PHP从页面中提取文章摘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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