开发者

Getting content of a website via PHP [closed]

It's difficult to tell what is b开发者_StackOverflow中文版eing asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

How do I get the content of a page via PHP? How do i grab the text of a blog post because most RRS feed only give the link to the article so i cant use that. Is there a PHP function for this or anyway about doing this. Please offer some suggestions :).


To just load a page, HTML and all, you can use fopen on the web address:

$page = file_get_contents('http://www.blog.com/one-example-post');

For more advanced handling of web pages, the cURL library will interact more cleverly with the remote server (for example, if there is HTTP authentication, or it's an https page).

Once you have the contents of the page, though, you're probably going to need to do some screen scraping (aka web scraping)... and you're in luck, since I just did this for another project. Here's a great library that I uncovered to help with this down-and-dirty technique. Good luck.


cURL is an option, especially if you need your application to behave like a browser (e.g. set a USER AGENT, etc.). You can also use [file_get_contents] (see: http://php.net/manual/en/function.file-get-contents.php) which is good enough for simple applications.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜