开发者

Using PHP, how to parse the title and meta tags from a HTML page? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

CodeIgniter: A Class/Library to help get meta tags from a web page?

I need to be able to get the TITLE and DESCIPTION m开发者_运维技巧etadata out of a page.

I've been trying to do this but I've been getting more errors than actual results. (I have an array of about 10 URLS, usually only about 2 of them give me the descrption. I have yet to get the title).

So how do I, in PHP, get the Desc and Title from a remote page, and if there is none or if there's an error, ignore it?

-Dylan


Use something like cURL (Checking things like the result isn't false and that the HTTP status is 200) to get the page and then Simple HTML DOM to parse it and extract the elements you want. (Remembering that the elements might not exist)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜